From 5f3c6bde7f856d08ef16554b489b5490977c4e51 Mon Sep 17 00:00:00 2001 From: Nate Abele Date: Fri, 18 Nov 2022 14:16:50 -0500 Subject: [PATCH] Switch `AUTO_INIT_CLASS` to global constant --- MIGRATING.md | 4 ++-- core/AutoConfigurable.php | 6 +++--- tests/cases/action/ResponseTest.php | 2 +- tests/cases/net/http/ServiceTest.php | 2 +- .../integration/data/source/database/adapter/MySqlTest.php | 2 +- .../data/source/database/adapter/PostgreSqlTest.php | 2 +- .../data/source/database/adapter/Sqlite3Test.php | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MIGRATING.md b/MIGRATING.md index 9f106eca1..bc6489c58 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -109,10 +109,10 @@ class MyClass { ### Defering class initialization -Prior to 2.0, class initialization (auto-dispatching to the `_init()` method) could be suppressed by passing `'init' => false` to the constructor. This has been replaced with a constant that is mixed in from the trait, and can be accessed by the class name, i.e.: +Prior to 2.0, class initialization (auto-dispatching to the `_init()` method) could be suppressed by passing `'init' => false` to the constructor. This has been replaced with a global constant that is defined in the `AutoConfigurable` trait: ```php -new MyClass([MyClass::AUTO_INIT_CLASS => false]) +new MyClass([AUTO_INIT_CLASS => false]) ``` Finally, as a result of this change, the `'init'` key is no longer automatically merged into the `$_config` property. Tests or other application logic depending on this behavior should be changed. diff --git a/core/AutoConfigurable.php b/core/AutoConfigurable.php index 729baed3c..dfc70731b 100644 --- a/core/AutoConfigurable.php +++ b/core/AutoConfigurable.php @@ -9,13 +9,13 @@ namespace lithium\core; +define('AUTO_INIT_CLASS', 'AUTO_INIT_CLASS'); + /** * Provides methods to configure an object. */ trait AutoConfigurable { - public const AUTO_INIT_CLASS = 'lithium\core\AutoConfigurable::AUTO_INIT_CLASS'; - /** * Stores configuration information for object instances at time of construction. * @@ -84,7 +84,7 @@ protected function _autoConfig(array $config, array $auto) { } protected function _autoInit($config) { - if (!isset($config[static::AUTO_INIT_CLASS]) || $config[static::AUTO_INIT_CLASS] !== false) { + if (!isset($config[AUTO_INIT_CLASS]) || $config[AUTO_INIT_CLASS] !== false) { $this->_init(); } } diff --git a/tests/cases/action/ResponseTest.php b/tests/cases/action/ResponseTest.php index c56b36f17..9bb003304 100644 --- a/tests/cases/action/ResponseTest.php +++ b/tests/cases/action/ResponseTest.php @@ -17,7 +17,7 @@ class ResponseTest extends \lithium\test\Unit { public $response = null; public function setUp() { - $this->response = new MockResponse([MockResponse::AUTO_INIT_CLASS => false]); + $this->response = new MockResponse([AUTO_INIT_CLASS => false]); } public function testTypeManipulation() { diff --git a/tests/cases/net/http/ServiceTest.php b/tests/cases/net/http/ServiceTest.php index 408683bdd..a50e18c18 100644 --- a/tests/cases/net/http/ServiceTest.php +++ b/tests/cases/net/http/ServiceTest.php @@ -29,7 +29,7 @@ public function setUp() { } public function testAllMethodsNoConnection() { - $http = new Service([Service::AUTO_INIT_CLASS => false]); + $http = new Service([AUTO_INIT_CLASS => false]); $this->assertEmpty($http->get()); $this->assertEmpty($http->post()); $this->assertEmpty($http->put()); diff --git a/tests/integration/data/source/database/adapter/MySqlTest.php b/tests/integration/data/source/database/adapter/MySqlTest.php index 497812de4..f7e909805 100644 --- a/tests/integration/data/source/database/adapter/MySqlTest.php +++ b/tests/integration/data/source/database/adapter/MySqlTest.php @@ -65,7 +65,7 @@ public function testEnabledFeatures() { * Tests that the object is initialized with the correct default values. */ public function testConstructorDefaults() { - $db = new MockMySql(['autoConnect' => false, MockMySql::AUTO_INIT_CLASS => false]); + $db = new MockMySql(['autoConnect' => false, AUTO_INIT_CLASS => false]); $result = $db->get('_config'); $expected = [ 'autoConnect' => false, 'encoding' => null,'persistent' => true, diff --git a/tests/integration/data/source/database/adapter/PostgreSqlTest.php b/tests/integration/data/source/database/adapter/PostgreSqlTest.php index b6966b58e..1bfdf3046 100644 --- a/tests/integration/data/source/database/adapter/PostgreSqlTest.php +++ b/tests/integration/data/source/database/adapter/PostgreSqlTest.php @@ -65,7 +65,7 @@ public function testEnabledFeatures() { * Tests that the object is initialized with the correct default values. */ public function testConstructorDefaults() { - $db = new MockPostgreSql(['autoConnect' => false, MockPostgreSql::AUTO_INIT_CLASS => false]); + $db = new MockPostgreSql(['autoConnect' => false, AUTO_INIT_CLASS => false]); $result = $db->get('_config'); $expected = [ 'autoConnect' => false, diff --git a/tests/integration/data/source/database/adapter/Sqlite3Test.php b/tests/integration/data/source/database/adapter/Sqlite3Test.php index 829b4ef8d..d223c298a 100644 --- a/tests/integration/data/source/database/adapter/Sqlite3Test.php +++ b/tests/integration/data/source/database/adapter/Sqlite3Test.php @@ -67,7 +67,7 @@ public function testEnabledFeatures() { * Tests that the object is initialized with the correct default values. */ public function testConstructorDefaults() { - $db = new MockSqlite3(['autoConnect' => false, MockSqlite3::AUTO_INIT_CLASS => false]); + $db = new MockSqlite3(['autoConnect' => false, AUTO_INIT_CLASS => false]); $result = $db->get('_config'); $expected = [ 'autoConnect' => false,