Skip to content

Commit

Permalink
Bug #18245: Make resolving DI references inside of arrays in dependen…
Browse files Browse the repository at this point in the history
…cies optional

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Andrii Vasyliev <sol@hiqdev.com>
  • Loading branch information
3 people authored Sep 14, 2020
1 parent acbefe6 commit 4e3cf83
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Yii Framework 2 Change Log
- Bug #15265: PostgreSQL > 10.0 is not pass tests with default value of timestamp CURRENT_TIMESTAMP (terabytesoftw)
- Bug #18232: Fail tests pgsql v-10.14, v-11.9, v-12-latest (terabytesoftw)
- Bug #16892: Validation error class was not applied to checkbox and radio when validationStateOn = self::VALIDATION_STATE_ON_INPUT (dan-szabo, samdark)

- Bug #18245: Make resolving DI references inside of arrays in dependencies optional (SamMousa, samdark, hiqsol)

2.0.37 August 07, 2020
----------------------
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ if you want to upgrade from version A to version C and there is
version B between A and C, you need to follow the instructions
for both A and B.

Upgrade from Yii 2.0.37
-----------------------

* Resolving DI references inside of arrays in dependencies was made optional and turned off by default. In order
to turn it on, set `resolveArrays` of container instance to `true`.

Upgrade from Yii 2.0.36
-----------------------

Expand Down
17 changes: 16 additions & 1 deletion di/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
* @property array $definitions The list of the object definitions or the loaded shared objects (type or ID =>
* definition or instance). This property is read-only.
*
* @property bool $resolveArrays whether to attempt to resolve elements in array dependencies
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
Expand Down Expand Up @@ -121,6 +123,10 @@ class Container extends Component
*/
private $_dependencies = [];

/**
* @var bool whether to attempt to resolve elements in array dependencies
*/
private $_resolveArrays = false;

/**
* Returns an instance of the requested class.
Expand Down Expand Up @@ -491,7 +497,7 @@ protected function resolveDependencies($dependencies, $reflection = null)
$class = $reflection->getName();
throw new InvalidConfigException("Missing required parameter \"$name\" when instantiating \"$class\".");
}
} elseif (is_array($dependency)) {
} elseif ($this->_resolveArrays && is_array($dependency)) {
$dependencies[$index] = $this->resolveDependencies($dependency, $reflection);
}
}
Expand Down Expand Up @@ -682,4 +688,13 @@ public function setSingletons(array $singletons)
$this->setSingleton($class, $definition);
}
}

/**
* @param bool $value whether to attempt to resolve elements in array dependencies
* @since 2.0.37
*/
public function setResolveArrays($value)
{
$this->_resolveArrays = (bool) $value;
}
}

0 comments on commit 4e3cf83

Please sign in to comment.