Skip to content

Commit

Permalink
Merge pull request #16600 from cakephp/errorlogger-deprecation
Browse files Browse the repository at this point in the history
Add compatibility shim for `errorLogger`
  • Loading branch information
othercorey committed Jul 5, 2022
2 parents 9d3a923 + 449868b commit 88c8d94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Error/ErrorTrap.php
Expand Up @@ -200,6 +200,12 @@ public function renderer(): ErrorRendererInterface
*/
public function logger(): ErrorLoggerInterface
{
$oldConfig = $this->getConfig('errorLogger');
if ($oldConfig !== null) {
deprecationWarning('The `errorLogger` configuration key is deprecated. Use `logger` instead.');
$this->setConfig(['logger' => $oldConfig, 'errorLogger' => null]);
}

/** @var class-string<\Cake\Error\ErrorLoggerInterface> $class */
$class = $this->getConfig('logger', $this->_defaultConfig['logger']);
if (!in_array(ErrorLoggerInterface::class, class_implements($class))) {
Expand Down
8 changes: 8 additions & 0 deletions tests/TestCase/Error/ErrorTrapTest.php
Expand Up @@ -82,6 +82,14 @@ public function testLoggerConfig()
$this->assertInstanceOf(ErrorLogger::class, $trap->logger());
}

public function testLoggerConfigCompatibility()
{
$this->deprecated(function () {
$trap = new ErrorTrap(['errorLogger' => ErrorLogger::class]);
$this->assertInstanceOf(ErrorLogger::class, $trap->logger());
});
}

public function testLoggerHandleUnsafeOverwrite()
{
$trap = new ErrorTrap();
Expand Down

0 comments on commit 88c8d94

Please sign in to comment.