8000 feature #20663 [DependencyInjection] replace DefinitionDecorator by C… · symfony/symfony@d27d445 · GitHub
[go: up one dir, main page]

Skip to content

Commit d27d445

Browse files
committed
feature #20663 [DependencyInjection] replace DefinitionDecorator by ChildDefinition (xabbuh)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DependencyInjection] replace DefinitionDecorator by ChildDefinition | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | TODO The DefinitionDecorator class does not deal with decorated services. It reflects a parent-child-relationship between definitions instead. To avoid confusion, this commit deprecates the existing DefinitionDecorator class and introduces a new DefinitionExtension class as replacement. Commits ------- 184f7ff replace DefinitionDecorator with ChildDefinition
2 parents 5b91ec8 + 184f7ff commit d27d445

38 files changed

+481
-304
lines changed

UPGRADE-3.3.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ ClassLoader
77
* The ApcClassLoader, WinCacheClassLoader and XcacheClassLoader classes have been deprecated
88
in favor of the `--apcu-autoloader` option introduced in composer 1.3
99

10+
DependencyInjection
11+
-------------------
12+
13+
* The `DefinitionDecorator` class is deprecated and will be removed in 4.0, use
14+
the `ChildDefinition` class instead.
15+
1016
Finder
1117
------
1218

UPGRADE-4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Debug
2222
DependencyInjection
2323
-------------------
2424

25+
* The `DefinitionDecorator` class has been removed. Use the `ChildDefinition`
26+
class instead.
27+
2528
* Using unsupported configuration keys in YAML configuration files raises an
2629
exception.
2730

src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
16-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
16+
use Symfony\Component\DependencyInjection\ChildDefinition;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818

1919
/**
@@ -36,7 +36,7 @@ public function __construct($key, $providerId)
3636
public function create(ContainerBuilder $container, $id, $config)
3737
{
3838
$container
39-
->setDefinition($id, new DefinitionDecorator($this->providerId))
39+
->setDefinition($id, new ChildDefinition($this->providerId))
4040
->addArgument($config['class'])
4141
->addArgument($config['property'])
4242
->addArgument($config['manager_name'])

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"require-dev": {
2424
"symfony/stopwatch": "~2.8|~3.0",
25-
"symfony/dependency-injection": "~2.8|~3.0",
25+
"symfony/dependency-injection": "~3.3",
2626
"symfony/form": "~3.0,>=3.0.5",
2727
"symfony/http-kernel": "~2.8|~3.0",
2828
"symfony/property-access": "~2.8|~3.0",
@@ -36,6 +36,9 @@
3636
"doctrine/dbal": "~2.4",
3737
"doctrine/orm": "~2.4,>=2.4.5"
3838
},
39+
"conflict": {
40+
"symfony/dependency-injection": "<3.3"
41+
},
3942
"suggest": {
4043
"symfony/form": "",
4144
"symfony/validator": "",

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\Cache\Adapter\RedisAdapter;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
1516
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
18-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2121

@@ -48,7 +48,7 @@ public function process(ContainerBuilder $container)
4848
continue;
4949
}
5050
$isLazy = $pool->isLazy();
51-
while ($adapter instanceof DefinitionDecorator) {
51+
while ($adapter instanceof ChildDefinition) {
5252
$adapter = $container->findDefinition($adapter->getParent());
5353
$isLazy = $isLazy || $adapter->isLazy();
5454
if ($t = $adapter->getTag('cache.pool')) {

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1616
use Symfony\Component\Cache\Adapter\AdapterInterface;
1717
use Symfony\Component\DependencyInjection\Alias;
18+
use Symfony\Component\DependencyInjection\ChildDefinition;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\ContainerInterface;
2021
use Symfony\Component\DependencyInjection\Definition;
21-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
2222
use Symfony\Component\DependencyInjection\Exception\LogicException;
2323
use Symfony\Component\DependencyInjection\Reference;
2424
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -436,7 +436,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
436436

437437
// Create MarkingStore
438438
if (isset($workflow['marking_store']['type'])) {
439-
$markingStoreDefinition = new DefinitionDecorator('workflow.marking_store.'.$workflow['marking_store']['type']);
439+
$markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']);
440440
foreach ($workflow['marking_store']['arguments'] as $argument) {
441441
$markingStoreDefinition->addArgument($argument);
442442
}
@@ -445,7 +445,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
445445
}
446446

447447
// Create Workflow
448-
$workflowDefinition = new DefinitionDecorator(sprintf('%s.abstract', $type));
448+
$workflowDefinition = new ChildDefinition(sprintf('%s.abstract', $type));
449449
$workflowDefinition->replaceArgument(0, $definitionDefinition);
450450
if (isset($markingStoreDefinition)) {
451451
$workflowDefinition->replaceArgument(1, $markingStoreDefinition);
@@ -762,7 +762,7 @@ private function createPackageDefinition($basePath, array $baseUrls, Reference $
762762
}
763763

764764
if (!$baseUrls) {
765-
$package = new DefinitionDecorator('assets.path_package');
765+
$package = new ChildDefinition('assets.path_package');
766766

767767
return $package
768768
->setPublic(false)
@@ -771,7 +771,7 @@ private function createPackageDefinition($basePath, array $baseUrls, Reference $
771771
;
772772
}
773773

774-
$package = new DefinitionDecorator('assets.url_package');
774+
$package = new ChildDefinition('assets.url_package');
775775

776776
return $package
777777
->setPublic(false)
@@ -786,7 +786,7 @@ private function createVersion(ContainerBuilder $container, $version, $format, $
786786
return new Reference('assets.empty_version_strategy');
787787
}
788788

789-
$def = new DefinitionDecorator('assets.static_version_strategy');
789+
$def = new ChildDefinition('assets.static_version_strategy');
790790
$def
791791
->replaceArgument(0, $version)
792792
->replaceArgument(1, $format)
@@ -1253,7 +1253,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
12531253
);
12541254
}
12551255
foreach ($config['pools'] as $name => $pool) {
1256-
$definition = new DefinitionDecorator($pool['adapter']);
1256+
$definition = new ChildDefinition($pool['adapter']);
12571257
$definition->setPublic($pool['public']);
12581258
unset($pool['adapter'], $pool['public']);
12591259

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
17-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1818
use Symfony\Component\DependencyInjection\Reference;
1919

2020
class CachePoolPassTest extends \PHPUnit_Framework_TestCase
@@ -38,7 +38,7 @@ public function testNamespaceArgumentIsReplaced()
3838
$adapter->addTag('cache.pool');
3939
$container->setDefinition('app.cache_adapter', $adapter);
4040
$container->setAlias('app.cache_adapter_alias', 'app.cache_adapter');
41-
$cachePool = new DefinitionDecorator('app.cache_adapter_alias');
41+
$cachePool = new ChildDefinition('app.cache_adapter_alias');
4242
$cachePool->addArgument(null);
4343
$cachePool->addTag('cache.pool');
4444
$container->setDefinition('app.cache_pool', $cachePool);
@@ -88,7 +88,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
8888
$adapter->setAbstract(true);
8989
$adapter->addTag('cache.pool');
9090
$container->setDefinition('app.cache_adapter', $adapter);
91-
$cachePool = new DefinitionDecorator('app.cache_adapter');
91+
$cachePool = new ChildDefinition('app.cache_adapter');
9292
$cachePool->addTag('cache.pool', array('foobar' => 123));
9393
$container->setDefinition('app.cache_pool', $cachePool);
9494

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2020
use Symfony\Component\Cache\Adapter\ProxyAdapter;
2121
use Symfony\Component\Cache\Adapter\RedisAdapter;
22+
use Symfony\Component\DependencyInjection\ChildDefinition;
2223
use Symfony\Component\DependencyInjection\ContainerBuilder;
23-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
2424
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
2525
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2626
use Symfony\Component\DependencyInjection\Reference;
@@ -754,14 +754,14 @@ protected function createContainerFromClosure($closure, $data = array())
754754
return $container;
755755
}
756756

757-
private function assertPathPackage(ContainerBuilder $container, DefinitionDecorator $package, $basePath, $version, $format)
757+
private function assertPathPackage(ContainerBuilder $container, ChildDefinition $package, $basePath, $version, $format)
758758
{
759759
$this->assertEquals('assets.path_package', $package->getParent());
760760
$this->assertEquals($basePath, $package->getArgument(0));
761761
$this->assertVersionStrategy($container, $package->getArgument(1), $version, $format);
762762
}
763763

764-
private function assertUrlPackage(ContainerBuilder $container, DefinitionDecorator $package, $baseUrls, $version, $format)
764+
private function assertUrlPackage(ContainerBuilder $container, ChildDefinition $package, $baseUrls, $version, $format)
765765
{
766766
$this->assertEquals('assets.url_package', $package->getParent());
767767
$this->assertEquals($baseUrls, $package->getArgument(0));
@@ -786,7 +786,7 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
786786

787787
$poolDefinition = $container->getDefinition($id);
788788

789-
$this->assertInstanceOf(DefinitionDecorator::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $id));
789+
$this->assertInstanceOf(ChildDefinition::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $id));
790790

791791
$this->assertTrue($poolDefinition->hasTag('cache.pool'), sprintf('Service definition "%s" is tagged with the "cache.pool" tag.', $id));
792792
$this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id));
@@ -799,7 +799,7 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
799799
do {
800800
$parentId = $parentDefinition->getParent();
801801
$parentDefinition = $container->findDefinition($parentId);
802-
} while ($parentDefinition instanceof DefinitionDecorator);
802+
} while ($parentDefinition instanceof ChildDefinition);
803803

804804
switch ($adapter) {
805805
case 'cache.adapter.apcu':

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9",
2020
"symfony/cache": "~3.2",
2121
"symfony/class-loader": "~3.2",
22-
"symfony/dependency-injection": "~3.2",
22+
"symfony/dependency-injection": "~3.3",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/event-dispatcher": "~2.8|~3.0",
2525
"symfony/http-foundation": "~3.1",

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;
1313

1414
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

@@ -156,7 +156,7 @@ protected function isRememberMeAware($config)
156156
protected function createListener($container, $id, $config, $userProvider)
157157
{
158158
$listenerId = $this->getListenerId();
159-
$listener = new DefinitionDecorator($listenerId);
159+
$listener = new ChildDefinition($listenerId);
160160
$listener->replaceArgument(4, $id);
161161
$listener->replaceArgument(5, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config)));
162162
$listener->replaceArgument(6, new Reference($this->createAuthenticationFailureHandler($container, $id, $config)));
@@ -174,12 +174,12 @@ protected function createAuthenticationSuccessHandler($container, $id, $config)
174174
$options = array_intersect_key($config, $this->defaultSuccessHandlerOptions);
175175

176176
if (isset($config['success_handler'])) {
177-
$successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.custom_success_handler'));
177+
$successHandler = $container->setDefinition($successHandlerId, new ChildDefinition('security.authentication.custom_success_handler'));
178178
$successHandler->replaceArgument(0, new Reference($config['success_handler']));
179179
$successHandler->replaceArgument(1, $options);
180180
$successHandler->replaceArgument(2, $id);
181181
} else {
182-
$successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler'));
182+
$successHandler = $container->setDefinition($successHandlerId, new ChildDefinition('security.authentication.success_handler'));
183183
$successHandler->addMethodCall('setOptions', array($options));
184184
$successHandler->addMethodCall('setProviderKey', array($id));
185185
}
@@ -193,11 +193,11 @@ protected function createAuthenticationFailureHandler($container, $id, $config)
193193
$options = array_intersect_key($config, $this->defaultFailureHandlerOptions);
194194

195195
if (isset($config['failure_handler'])) {
196-
$failureHandler = $container->setDefinition($id, new DefinitionDecorator('security.authentication.custom_failure_handler'));
196+
$failureHandler = $container->setDefinition($id, new ChildDefinition('security.authentication.custom_failure_handler'));
197197
$failureHandler->replaceArgument(0, new Reference($config['failure_handler']));
198198
$failureHandler->replaceArgument(1, $options);
199199
} else {
200-
$failureHandler = $container->setDefinition($id, new DefinitionDecorator('security.authentication.failure_handler'));
200+
$failureHandler = $container->setDefinition($id, new ChildDefinition('security.authentication.failure_handler'));
201201
$failureHandler->addMethodCall('setOptions', array($options));
202202
}
203203

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;
1313

1414
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

@@ -63,7 +63,7 @@ protected function createAuthProvider(ContainerBuilder $container, $id, $config,
6363
{
6464
$provider = 'security.authentication.provider.dao.'.$id;
6565
$container
66-
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao'))
66+
->setDefinition($provider, new ChildDefinition('security.authentication.provider.dao'))
6767
->replaceArgument(0, new Reference($userProviderId))
6868
->replaceArgument(1, new Reference('security.user_checker.'.$id))
6969
->replaceArgument(2, $id)
@@ -88,7 +88,7 @@ protected function createEntryPoint($container, $id, $config, $defaultEntryPoint
8888
{
8989
$entryPointId = 'security.authentication.form_entry_point.'.$id;
9090
$container
91-
->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.form_entry_point'))
91+
->setDefinition($entryPointId, new ChildDefinition('security.authentication.form_entry_point'))
9292
->addArgument(new Reference('security.http_utils'))
9393
->addArgument($config['login_path'])
9494
->addArgument($config['use_forward'])

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginLdapFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;
1313

1414
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

@@ -28,7 +28,7 @@ protected function createAuthProvider(ContainerBuilder $container, $id, $config,
2828
{
2929
$provider = 'security.authentication.provider.ldap_bind.'.$id;
3030
$container
31-
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.ldap_bind'))
31+
->setDefinition($provider, new ChildDefinition('security.authentication.provider.ldap_bind'))
3232
->replaceArgument(0, new Reference($userProviderId))
3333
->replaceArgument(1, new Reference('security.user_checker.'.$id))
3434
->replaceArgument(2, $id)

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;
1313

1414
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15+
use Symfony\Component\DependencyInjection\ChildDefinition;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

1919
/**
@@ -65,7 +65,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
6565
// configure the GuardAuthenticationFactory to have the dynamic constructor arguments
6666
$providerId = 'security.authentication.provider.guard.'.$id;
6767
$container
68-
->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.guard'))
68+
->setDefinition($providerId, new ChildDefinition('security.authentication.provider.guard'))
6969
->replaceArgument(0, $authenticatorReferences)
7070
->replaceArgument(1, new Reference($userProvider))
7171
->replaceArgument(2, $id)
@@ -74,7 +74,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
7474

7575
// listener
7676
$listenerId = 'security.authentication.listener.guard.'.$id;
77-
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.guard'));
77+
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.guard'));
7878
$listener->replaceArgument(2, $id);
7979
$listener->replaceArgument(3, $authenticatorReferences);
8080

0 commit comments

Comments
 (0)
0