From 6fbd0af9a494826797ec99c6342d8817ea2a4f69 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 4 Jul 2022 16:39:54 -0400 Subject: [PATCH 1/2] Add compatibility shim for `errorLogger` Users with custom error logging will be using the `errorLogger` key. In order for them to complete their upgrade to `ErrorTrap` they need to use the `logger` key instead. --- src/Error/ErrorTrap.php | 6 ++++++ tests/TestCase/Error/ErrorTrapTest.php | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Error/ErrorTrap.php b/src/Error/ErrorTrap.php index 12dedd94174..d9dac806b17 100644 --- a/src/Error/ErrorTrap.php +++ b/src/Error/ErrorTrap.php @@ -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); + } + /** @var class-string<\Cake\Error\ErrorLoggerInterface> $class */ $class = $this->getConfig('logger', $this->_defaultConfig['logger']); if (!in_array(ErrorLoggerInterface::class, class_implements($class))) { diff --git a/tests/TestCase/Error/ErrorTrapTest.php b/tests/TestCase/Error/ErrorTrapTest.php index 8b43f851424..86cb7f870cc 100644 --- a/tests/TestCase/Error/ErrorTrapTest.php +++ b/tests/TestCase/Error/ErrorTrapTest.php @@ -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(); From 449868bb873518389f5f5810627b849880fe09dc Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 4 Jul 2022 21:54:31 -0400 Subject: [PATCH 2/2] Don't emit deprecation warnings on every error. --- src/Error/ErrorTrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Error/ErrorTrap.php b/src/Error/ErrorTrap.php index d9dac806b17..c1f743e8222 100644 --- a/src/Error/ErrorTrap.php +++ b/src/Error/ErrorTrap.php @@ -203,7 +203,7 @@ 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); + $this->setConfig(['logger' => $oldConfig, 'errorLogger' => null]); } /** @var class-string<\Cake\Error\ErrorLoggerInterface> $class */