8000 minor #19608 [DependencyInjection] ContainerBuilder: Remove obsolete … · symfony/symfony@9784301 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9784301

Browse files
committed
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](#7007). Thus, this code [is not meant to be used since 3.0 and can be removed](#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
2 parents 74b8561 + daa7d00 commit 9784301

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
5050
*/
5151
private $definitions = array();
5252

53-
/**
54-
* @var Definition[]
55-
*/
56-
private $obsoleteDefinitions = array();
57-
5853
/**
5954
* @var Alias[]
6055
*/
@@ -346,21 +341,8 @@ public function set($id, $service)
346341
{
347342
$id = strtolower($id);
348343

349-
if ($this->isFrozen()) {
350-
// setting a synthetic service on a frozen container is alright
351-
if (
352-
(!isset($this->definitions[$id]) && !isset($this->obsoleteDefinitions[$id]))
353-
||
354-
(isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())
355-
||
356-
(isset($this->obsoleteDefinitions[$id]) && !$this->obsoleteDefinitions[$id]->isSynthetic())
357-
) {
358-
throw new BadMethodCallException(sprintf('Setting service "%s" on a frozen container is not allowed.', $id));
359-
}
360-
}
361-
362-
if (isset($this->definitions[$id])) {
363-
$this->obsoleteDefinitions[$id] = $this->definitions[$id];
344+
if ($this->isFrozen() && (!isset($this->definitions[$id]) || !$this->definitions[$id]->isSynthetic())) {
345+
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a frozen container is not allowed.', $id));
364346
}
365347

366348
unset($this->definitions[$id], $this->aliasDefinitions[$id]);

0 commit comments

Comments
 (0)
0