Skip to content

Commit

Permalink
Switch AUTO_INIT_CLASS to global constant
Browse files Browse the repository at this point in the history
  • Loading branch information
nateabele committed Nov 18, 2022
1 parent 0675391 commit 5f3c6bd
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions core/AutoConfigurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/action/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/net/http/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5f3c6bd

Please sign in to comment.