minor #19608 [DependencyInjection] ContainerBuilder: Remove obsolete definitions (ogizanagi)
This PR was merged into the 3.1 branch.
Discussion
----------
[DependencyInjection] ContainerBuilder: Remove obsolete definitions
| Q | A
| ------------- | ---
| Branch? | 3.1
| Bug fix? | yes
| New feature? |no
| BC breaks? | may be considered
| Deprecations? | may be considered
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
IIUC, [the obsolete definitions thing was tied to scoped & sync services](https://github.com/symfony/symfony/pull/7007).
Thus, this code [is not meant to be used since 3.0 and can be removed](https://github.com/symfony/symfony/pull/13289).
However, it may be considered as a BC break and would require introducing a new deprecation instead, because the current code allows to set a service on a frozen container if it has an obsolete synthetic definition...which is weird, isn't it ? (I doubt this feature was explicitly intended to allow setting a synthetic service more than once, and it wasn't before sync services introduction)
I suggest this as a patch for 3.1, under the pretext of forgotten code tied to a previous deprecation & feature removal, but let me know if it should be considered differently.
Commits
-------
daa7d00
[DependencyInjection] ContainerBuilder: Remove obsolete definitions
This commit is contained in:
commit
9784301b1f
@ -50,11 +50,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
*/
|
*/
|
||||||
private $definitions = array();
|
private $definitions = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Definition[]
|
|
||||||
*/
|
|
||||||
private $obsoleteDefinitions = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Alias[]
|
* @var Alias[]
|
||||||
*/
|
*/
|
||||||
@ -346,21 +341,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
{
|
{
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
if ($this->isFrozen()) {
|
if ($this->isFrozen() && (!isset($this->definitions[$id]) || !$this->definitions[$id]->isSynthetic())) {
|
||||||
// setting a synthetic service on a frozen container is alright
|
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a frozen container is not allowed.', $id));
|
||||||
if (
|
|
||||||
(!isset($this->definitions[$id]) && !isset($this->obsoleteDefinitions[$id]))
|
|
||||||
||
|
|
||||||
(isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())
|
|
||||||
||
|
|
||||||
(isset($this->obsoleteDefinitions[$id]) && !$this->obsoleteDefinitions[$id]->isSynthetic())
|
|
||||||
) {
|
|
||||||
throw new BadMethodCallException(sprintf('Setting service "%s" on a frozen container is not allowed.', $id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->definitions[$id])) {
|
|
||||||
$this->obsoleteDefinitions[$id] = $this->definitions[$id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->definitions[$id], $this->aliasDefinitions[$id]);
|
unset($this->definitions[$id], $this->aliasDefinitions[$id]);
|
||||||
|
Reference in New Issue
Block a user