Skip to content

Commit 5f3c6bd

Browse files
committed
Switch AUTO_INIT_CLASS to global constant
1 parent 0675391 commit 5f3c6bd

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

MIGRATING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ class MyClass {
109109

110110
### Defering class initialization
111111

112-
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.:
112+
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:
113113

114114
```php
115-
new MyClass([MyClass::AUTO_INIT_CLASS => false])
115+
new MyClass([AUTO_INIT_CLASS => false])
116116
```
117117

118118
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.

core/AutoConfigurable.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
namespace lithium\core;
1111

12+
define('AUTO_INIT_CLASS', 'AUTO_INIT_CLASS');
13+
1214
/**
1315
* Provides methods to configure an object.
1416
*/
1517
trait AutoConfigurable {
1618

17-
public const AUTO_INIT_CLASS = 'lithium\core\AutoConfigurable::AUTO_INIT_CLASS';
18-
1919
/**
2020
* Stores configuration information for object instances at time of construction.
2121
*
@@ -84,7 +84,7 @@ protected function _autoConfig(array $config, array $auto) {
8484
}
8585

8686
protected function _autoInit($config) {
87-
if (!isset($config[static::AUTO_INIT_CLASS]) || $config[static::AUTO_INIT_CLASS] !== false) {
87+
if (!isset($config[AUTO_INIT_CLASS]) || $config[AUTO_INIT_CLASS] !== false) {
8888
$this->_init();
8989
}
9090
}

tests/cases/action/ResponseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ResponseTest extends \lithium\test\Unit {
1717
public $response = null;
1818

1919
public function setUp() {
20-
$this->response = new MockResponse([MockResponse::AUTO_INIT_CLASS => false]);
20+
$this->response = new MockResponse([AUTO_INIT_CLASS => false]);
2121
}
2222

2323
public function testTypeManipulation() {

tests/cases/net/http/ServiceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setUp() {
2929
}
3030

3131
public function testAllMethodsNoConnection() {
32-
$http = new Service([Service::AUTO_INIT_CLASS => false]);
32+
$http = new Service([AUTO_INIT_CLASS => false]);
3333
$this->assertEmpty($http->get());
3434
$this->assertEmpty($http->post());
3535
$this->assertEmpty($http->put());

tests/integration/data/source/database/adapter/MySqlTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testEnabledFeatures() {
6565
* Tests that the object is initialized with the correct default values.
6666
*/
6767
public function testConstructorDefaults() {
68-
$db = new MockMySql(['autoConnect' => false, MockMySql::AUTO_INIT_CLASS => false]);
68+
$db = new MockMySql(['autoConnect' => false, AUTO_INIT_CLASS => false]);
6969
$result = $db->get('_config');
7070
$expected = [
7171
'autoConnect' => false, 'encoding' => null,'persistent' => true,

tests/integration/data/source/database/adapter/PostgreSqlTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testEnabledFeatures() {
6565
* Tests that the object is initialized with the correct default values.
6666
*/
6767
public function testConstructorDefaults() {
68-
$db = new MockPostgreSql(['autoConnect' => false, MockPostgreSql::AUTO_INIT_CLASS => false]);
68+
$db = new MockPostgreSql(['autoConnect' => false, AUTO_INIT_CLASS => false]);
6969
$result = $db->get('_config');
7070
$expected = [
7171
'autoConnect' => false,

tests/integration/data/source/database/adapter/Sqlite3Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testEnabledFeatures() {
6767
* Tests that the object is initialized with the correct default values.
6868
*/
6969
public function testConstructorDefaults() {
70-
$db = new MockSqlite3(['autoConnect' => false, MockSqlite3::AUTO_INIT_CLASS => false]);
70+
$db = new MockSqlite3(['autoConnect' => false, AUTO_INIT_CLASS => false]);
7171
$result = $db->get('_config');
7272
$expected = [
7373
'autoConnect' => false,

0 commit comments

Comments
 (0)