Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility shim for errorLogger #16600

Merged
merged 2 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]);
}
Copy link
Member

@othercorey othercorey Jul 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this clear the old config so the warning isn't triggered every time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!


/** @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