Browse Source

Merge pull request #16600 from cakephp/errorlogger-deprecation

Add compatibility shim for `errorLogger`
othercorey 3 years ago
parent
commit
88c8d945fe
2 changed files with 14 additions and 0 deletions
  1. 6 0
      src/Error/ErrorTrap.php
  2. 8 0
      tests/TestCase/Error/ErrorTrapTest.php

+ 6 - 0
src/Error/ErrorTrap.php

@@ -200,6 +200,12 @@ class ErrorTrap
      */
     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))) {

+ 8 - 0
tests/TestCase/Error/ErrorTrapTest.php

@@ -82,6 +82,14 @@ class ErrorTrapTest extends TestCase
         $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();