Skip to content

Commit 0540c6f

Browse files
committed
review
1 parent 7b0d6ed commit 0540c6f

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
5.3.0
55
-----
66

7-
* added `ServicesConfigurator::remove()` in the PHP-DSL
7+
* added `ServicesConfigurator::remove()` in the PHP-DSL
88

99
5.2.0
1010
-----

src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractServiceConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ final public function get(string $id): ServiceConfigurator
8484
/**
8585
* Removes an already defined service definition or alias.
8686
*/
87-
final public function remove(string $id)
87+
final public function remove(string $id): ServicesConfigurator
8888
{
8989
$this->__destruct();
9090

91-
$this->parent->remove($id);
91+
return $this->parent->remove($id);
9292
}
9393

9494
/**

src/Symfony/Component/DependencyInjection/Loader/Configurator/ServiceConfigurator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ServiceConfigurator extends AbstractServiceConfigurator
4545
private $instanceof;
4646
private $allowParent;
4747
private $path;
48+
private $destructed = false;
4849

4950
public function __construct(ContainerBuilder $container, array $instanceof, bool $allowParent, ServicesConfigurator $parent, Definition $definition, $id, array $defaultTags, string $path = null)
5051
{
@@ -58,6 +59,11 @@ public function __construct(ContainerBuilder $container, array $instanceof, bool
5859

5960
public function __destruct()
6061
{
62+
if ($this->destructed) {
63+
return;
64+
}
65+
$this->destructed = true;
66+
6167
parent::__destruct();
6268

6369
$this->container->removeBindings($this->id);

src/Symfony/Component/DependencyInjection/Loader/Configurator/ServicesConfigurator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,18 @@ final public function set(?string $id, string $class = null): ServiceConfigurato
9393

9494
$configurator = new ServiceConfigurator($this->container, $this->instanceof, true, $this, $definition, $id, $defaults->getTags(), $this->path);
9595

96-
return null === $class ? $configurator : $configurator->class($class);
96+
return null !== $class ? $configurator->class($class) : $configurator;
9797
}
9898

9999
/**
100100
* Removes an already defined service definition or alias.
101101
*/
102-
final public function remove(string $id)
102+
final public function remove(string $id): self
103103
{
104104
$this->container->removeDefinition($id);
105105
$this->container->removeAlias($id);
106+
107+
return $this;
106108
}
107109

108110
/**

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/remove.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
return function (ContainerConfigurator $c) {
66
$services = $c->services()->defaults()->public();
77

8-
$services->set('foo', FooService::class);
9-
$services->remove('foo');
8+
$services
9+
->set('foo', FooService::class)
10+
->remove('foo')
1011

11-
$services->set('baz', BazService::class);
12-
$services->alias('baz-alias', 'baz');
13-
$services->remove('baz-alias');
12+
->set('baz', BazService::class)
13+
->alias('baz-alias', 'baz')
14+
->remove('baz-alias')
1415

15-
$services->remove('bat'); // noop
16+
->remove('bat'); // noop
1617
};
17-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy