From 184f7ff125057bc3ec83ebfeeb77e29b85ef9e6c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 28 Nov 2016 08:50:06 +0100 Subject: [PATCH] replace DefinitionDecorator with ChildDefinition 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 ChildDefinition class as replacement. --- UPGRADE-3.3.md | 6 + UPGRADE-4.0.md | 3 + .../Security/UserProvider/EntityFactory.php | 4 +- src/Symfony/Bridge/Doctrine/composer.json | 5 +- .../Compiler/CachePoolPass.php | 4 +- .../FrameworkExtension.php | 14 +- .../Compiler/CachePoolPassTest.php | 6 +- .../FrameworkExtensionTest.php | 10 +- .../Bundle/FrameworkBundle/composer.json | 2 +- .../Security/Factory/AbstractFactory.php | 12 +- .../Security/Factory/FormLoginFactory.php | 6 +- .../Security/Factory/FormLoginLdapFactory.php | 4 +- .../Factory/GuardAuthenticationFactory.php | 6 +- .../Security/Factory/HttpBasicFactory.php | 8 +- .../Security/Factory/HttpBasicLdapFactory.php | 6 +- .../Security/Factory/HttpDigestFactory.php | 8 +- .../Security/Factory/JsonLoginFactory.php | 6 +- .../Security/Factory/RememberMeFactory.php | 8 +- .../Security/Factory/RemoteUserFactory.php | 6 +- .../Security/Factory/SimpleFormFactory.php | 8 +- .../SimplePreAuthenticationFactory.php | 6 +- .../Security/Factory/X509Factory.php | 6 +- .../Security/UserProvider/InMemoryFactory.php | 6 +- .../Security/UserProvider/LdapFactory.php | 4 +- .../DependencyInjection/SecurityExtension.php | 24 +-- .../Tests/Functional/SetAclCommandTest.php | 3 + .../Bundle/SecurityBundle/composer.json | 1 + .../DependencyInjection/CHANGELOG.md | 5 + .../DependencyInjection/ChildDefinition.php | 199 ++++++++++++++++++ .../ResolveDefinitionTemplatesPass.php | 18 +- .../DependencyInjection/ContainerBuilder.php | 2 +- .../DefinitionDecorator.php | 182 +--------------- .../Loader/XmlFileLoader.php | 6 +- .../Loader/YamlFileLoader.php | 4 +- .../Tests/ChildDefinitionTest.php | 128 +++++++++++ .../ResolveDefinitionTemplatesPassTest.php | 50 ++--- .../Tests/ContainerBuilderTest.php | 6 +- .../Tests/DefinitionDecoratorTest.php | 3 + 38 files changed, 481 insertions(+), 304 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/ChildDefinition.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index c94084833e..104e45d48a 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -7,6 +7,12 @@ ClassLoader * The ApcClassLoader, WinCacheClassLoader and XcacheClassLoader classes have been deprecated in favor of the `--apcu-autoloader` option introduced in composer 1.3 +DependencyInjection +------------------- + + * The `DefinitionDecorator` class is deprecated and will be removed in 4.0, use + the `ChildDefinition` class instead. + Finder ------ diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 185b4a3d12..e936549ba6 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -22,6 +22,9 @@ Debug DependencyInjection ------------------- + * The `DefinitionDecorator` class has been removed. Use the `ChildDefinition` + class instead. + * Using unsupported configuration keys in YAML configuration files raises an exception. diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php index ebcdf82f58..49c528ba00 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php @@ -13,7 +13,7 @@ namespace Symfony\Bridge\Doctrine\DependencyInjection\Security\UserProvider; use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; /** @@ -36,7 +36,7 @@ class EntityFactory implements UserProviderFactoryInterface public function create(ContainerBuilder $container, $id, $config) { $container - ->setDefinition($id, new DefinitionDecorator($this->providerId)) + ->setDefinition($id, new ChildDefinition($this->providerId)) ->addArgument($config['class']) ->addArgument($config['property']) ->addArgument($config['manager_name']) diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index b7eedf5f1e..491adb8f91 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -22,7 +22,7 @@ }, "require-dev": { "symfony/stopwatch": "~2.8|~3.0", - "symfony/dependency-injection": "~2.8|~3.0", + "symfony/dependency-injection": "~3.3", "symfony/form": "~3.0,>=3.0.5", "symfony/http-kernel": "~2.8|~3.0", "symfony/property-access": "~2.8|~3.0", @@ -36,6 +36,9 @@ "doctrine/dbal": "~2.4", "doctrine/orm": "~2.4,>=2.4.5" }, + "conflict": { + "symfony/dependency-injection": "<3.3" + }, "suggest": { "symfony/form": "", "symfony/validator": "", diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index e4e3bc3506..e0be688fc8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -12,10 +12,10 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -48,7 +48,7 @@ class CachePoolPass implements CompilerPassInterface continue; } $isLazy = $pool->isLazy(); - while ($adapter instanceof DefinitionDecorator) { + while ($adapter instanceof ChildDefinition) { $adapter = $container->findDefinition($adapter->getParent()); $isLazy = $isLazy || $adapter->isLazy(); if ($t = $adapter->getTag('cache.pool')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 68aad4a6a7..00cd236dc1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -15,10 +15,10 @@ use Doctrine\Common\Annotations\Reader; use Symfony\Bridge\Monolog\Processor\DebugProcessor; use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; @@ -436,7 +436,7 @@ class FrameworkExtension extends Extension // Create MarkingStore if (isset($workflow['marking_store']['type'])) { - $markingStoreDefinition = new DefinitionDecorator('workflow.marking_store.'.$workflow['marking_store']['type']); + $markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']); foreach ($workflow['marking_store']['arguments'] as $argument) { $markingStoreDefinition->addArgument($argument); } @@ -445,7 +445,7 @@ class FrameworkExtension extends Extension } // Create Workflow - $workflowDefinition = new DefinitionDecorator(sprintf('%s.abstract', $type)); + $workflowDefinition = new ChildDefinition(sprintf('%s.abstract', $type)); $workflowDefinition->replaceArgument(0, $definitionDefinition); if (isset($markingStoreDefinition)) { $workflowDefinition->replaceArgument(1, $markingStoreDefinition); @@ -762,7 +762,7 @@ class FrameworkExtension extends Extension } if (!$baseUrls) { - $package = new DefinitionDecorator('assets.path_package'); + $package = new ChildDefinition('assets.path_package'); return $package ->setPublic(false) @@ -771,7 +771,7 @@ class FrameworkExtension extends Extension ; } - $package = new DefinitionDecorator('assets.url_package'); + $package = new ChildDefinition('assets.url_package'); return $package ->setPublic(false) @@ -786,7 +786,7 @@ class FrameworkExtension extends Extension return new Reference('assets.empty_version_strategy'); } - $def = new DefinitionDecorator('assets.static_version_strategy'); + $def = new ChildDefinition('assets.static_version_strategy'); $def ->replaceArgument(0, $version) ->replaceArgument(1, $format) @@ -1253,7 +1253,7 @@ class FrameworkExtension extends Extension ); } foreach ($config['pools'] as $name => $pool) { - $definition = new DefinitionDecorator($pool['adapter']); + $definition = new ChildDefinition($pool['adapter']); $definition->setPublic($pool['public']); unset($pool['adapter'], $pool['public']); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php index 25a706c3a4..1d297a1507 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php @@ -12,9 +12,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; class CachePoolPassTest extends \PHPUnit_Framework_TestCase @@ -38,7 +38,7 @@ class CachePoolPassTest extends \PHPUnit_Framework_TestCase $adapter->addTag('cache.pool'); $container->setDefinition('app.cache_adapter', $adapter); $container->setAlias('app.cache_adapter_alias', 'app.cache_adapter'); - $cachePool = new DefinitionDecorator('app.cache_adapter_alias'); + $cachePool = new ChildDefinition('app.cache_adapter_alias'); $cachePool->addArgument(null); $cachePool->addTag('cache.pool'); $container->setDefinition('app.cache_pool', $cachePool); @@ -88,7 +88,7 @@ class CachePoolPassTest extends \PHPUnit_Framework_TestCase $adapter->setAbstract(true); $adapter->addTag('cache.pool'); $container->setDefinition('app.cache_adapter', $adapter); - $cachePool = new DefinitionDecorator('app.cache_adapter'); + $cachePool = new ChildDefinition('app.cache_adapter'); $cachePool->addTag('cache.pool', array('foobar' => 123)); $container->setDefinition('app.cache_pool', $cachePool); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 4388b70afe..666dd3c405 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -19,8 +19,8 @@ use Symfony\Component\Cache\Adapter\DoctrineAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\ProxyAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; @@ -754,14 +754,14 @@ abstract class FrameworkExtensionTest extends TestCase return $container; } - private function assertPathPackage(ContainerBuilder $container, DefinitionDecorator $package, $basePath, $version, $format) + private function assertPathPackage(ContainerBuilder $container, ChildDefinition $package, $basePath, $version, $format) { $this->assertEquals('assets.path_package', $package->getParent()); $this->assertEquals($basePath, $package->getArgument(0)); $this->assertVersionStrategy($container, $package->getArgument(1), $version, $format); } - private function assertUrlPackage(ContainerBuilder $container, DefinitionDecorator $package, $baseUrls, $version, $format) + private function assertUrlPackage(ContainerBuilder $container, ChildDefinition $package, $baseUrls, $version, $format) { $this->assertEquals('assets.url_package', $package->getParent()); $this->assertEquals($baseUrls, $package->getArgument(0)); @@ -786,7 +786,7 @@ abstract class FrameworkExtensionTest extends TestCase $poolDefinition = $container->getDefinition($id); - $this->assertInstanceOf(DefinitionDecorator::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $id)); + $this->assertInstanceOf(ChildDefinition::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $id)); $this->assertTrue($poolDefinition->hasTag('cache.pool'), sprintf('Service definition "%s" is tagged with the "cache.pool" tag.', $id)); $this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id)); @@ -799,7 +799,7 @@ abstract class FrameworkExtensionTest extends TestCase do { $parentId = $parentDefinition->getParent(); $parentDefinition = $container->findDefinition($parentId); - } while ($parentDefinition instanceof DefinitionDecorator); + } while ($parentDefinition instanceof ChildDefinition); switch ($adapter) { case 'cache.adapter.apcu': diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 0e43050e03..3dae58081b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -19,7 +19,7 @@ "php": ">=5.5.9", "symfony/cache": "~3.2", "symfony/class-loader": "~3.2", - "symfony/dependency-injection": "~3.2", + "symfony/dependency-injection": "~3.3", "symfony/config": "~2.8|~3.0", "symfony/event-dispatcher": "~2.8|~3.0", "symfony/http-foundation": "~3.1", diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php index cdb0a96fe4..356e9f8327 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -156,7 +156,7 @@ abstract class AbstractFactory implements SecurityFactoryInterface protected function createListener($container, $id, $config, $userProvider) { $listenerId = $this->getListenerId(); - $listener = new DefinitionDecorator($listenerId); + $listener = new ChildDefinition($listenerId); $listener->replaceArgument(4, $id); $listener->replaceArgument(5, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config))); $listener->replaceArgument(6, new Reference($this->createAuthenticationFailureHandler($container, $id, $config))); @@ -174,12 +174,12 @@ abstract class AbstractFactory implements SecurityFactoryInterface $options = array_intersect_key($config, $this->defaultSuccessHandlerOptions); if (isset($config['success_handler'])) { - $successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.custom_success_handler')); + $successHandler = $container->setDefinition($successHandlerId, new ChildDefinition('security.authentication.custom_success_handler')); $successHandler->replaceArgument(0, new Reference($config['success_handler'])); $successHandler->replaceArgument(1, $options); $successHandler->replaceArgument(2, $id); } else { - $successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler')); + $successHandler = $container->setDefinition($successHandlerId, new ChildDefinition('security.authentication.success_handler')); $successHandler->addMethodCall('setOptions', array($options)); $successHandler->addMethodCall('setProviderKey', array($id)); } @@ -193,11 +193,11 @@ abstract class AbstractFactory implements SecurityFactoryInterface $options = array_intersect_key($config, $this->defaultFailureHandlerOptions); if (isset($config['failure_handler'])) { - $failureHandler = $container->setDefinition($id, new DefinitionDecorator('security.authentication.custom_failure_handler')); + $failureHandler = $container->setDefinition($id, new ChildDefinition('security.authentication.custom_failure_handler')); $failureHandler->replaceArgument(0, new Reference($config['failure_handler'])); $failureHandler->replaceArgument(1, $options); } else { - $failureHandler = $container->setDefinition($id, new DefinitionDecorator('security.authentication.failure_handler')); + $failureHandler = $container->setDefinition($id, new ChildDefinition('security.authentication.failure_handler')); $failureHandler->addMethodCall('setOptions', array($options)); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php index 021c050b79..24f0b98ae6 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -63,7 +63,7 @@ class FormLoginFactory extends AbstractFactory { $provider = 'security.authentication.provider.dao.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.dao')) ->replaceArgument(0, new Reference($userProviderId)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->replaceArgument(2, $id) @@ -88,7 +88,7 @@ class FormLoginFactory extends AbstractFactory { $entryPointId = 'security.authentication.form_entry_point.'.$id; $container - ->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.form_entry_point')) + ->setDefinition($entryPointId, new ChildDefinition('security.authentication.form_entry_point')) ->addArgument(new Reference('security.http_utils')) ->addArgument($config['login_path']) ->addArgument($config['use_forward']) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginLdapFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginLdapFactory.php index 2932f2c102..cd4158dfa5 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginLdapFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginLdapFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -28,7 +28,7 @@ class FormLoginLdapFactory extends FormLoginFactory { $provider = 'security.authentication.provider.ldap_bind.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.ldap_bind')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.ldap_bind')) ->replaceArgument(0, new Reference($userProviderId)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->replaceArgument(2, $id) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php index 67bdeceb34..8676e6c2f3 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php @@ -12,8 +12,8 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; /** @@ -65,7 +65,7 @@ class GuardAuthenticationFactory implements SecurityFactoryInterface // configure the GuardAuthenticationFactory to have the dynamic constructor arguments $providerId = 'security.authentication.provider.guard.'.$id; $container - ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.guard')) + ->setDefinition($providerId, new ChildDefinition('security.authentication.provider.guard')) ->replaceArgument(0, $authenticatorReferences) ->replaceArgument(1, new Reference($userProvider)) ->replaceArgument(2, $id) @@ -74,7 +74,7 @@ class GuardAuthenticationFactory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.guard.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.guard')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.guard')); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, $authenticatorReferences); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php index 162ea05157..3bfb50718b 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -27,7 +27,7 @@ class HttpBasicFactory implements SecurityFactoryInterface { $provider = 'security.authentication.provider.dao.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.dao')) ->replaceArgument(0, new Reference($userProvider)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->replaceArgument(2, $id) @@ -38,7 +38,7 @@ class HttpBasicFactory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.basic.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.basic')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.basic')); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, new Reference($entryPointId)); @@ -73,7 +73,7 @@ class HttpBasicFactory implements SecurityFactoryInterface $entryPointId = 'security.authentication.basic_entry_point.'.$id; $container - ->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.basic_entry_point')) + ->setDefinition($entryPointId, new ChildDefinition('security.authentication.basic_entry_point')) ->addArgument($config['realm']) ; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicLdapFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicLdapFactory.php index 2b7e6201df..961af71461 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicLdapFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicLdapFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -29,7 +29,7 @@ class HttpBasicLdapFactory extends HttpBasicFactory { $provider = 'security.authentication.provider.ldap_bind.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.ldap_bind')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.ldap_bind')) ->replaceArgument(0, new Reference($userProvider)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->replaceArgument(2, $id) @@ -42,7 +42,7 @@ class HttpBasicLdapFactory extends HttpBasicFactory // listener $listenerId = 'security.authentication.listener.basic.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.basic')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.basic')); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, new Reference($entryPointId)); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php index a360504572..bedc87864c 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -27,7 +27,7 @@ class HttpDigestFactory implements SecurityFactoryInterface { $provider = 'security.authentication.provider.dao.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.dao')) ->replaceArgument(0, new Reference($userProvider)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->replaceArgument(2, $id) @@ -38,7 +38,7 @@ class HttpDigestFactory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.digest.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.digest')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.digest')); $listener->replaceArgument(1, new Reference($userProvider)); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, new Reference($entryPointId)); @@ -75,7 +75,7 @@ class HttpDigestFactory implements SecurityFactoryInterface $entryPointId = 'security.authentication.digest_entry_point.'.$id; $container - ->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.digest_entry_point')) + ->setDefinition($entryPointId, new ChildDefinition('security.authentication.digest_entry_point')) ->addArgument($config['realm']) ->addArgument($config['secret']) ; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php index dbd29fa53c..2bda0ea9dc 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php @@ -11,8 +11,8 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; /** @@ -51,7 +51,7 @@ class JsonLoginFactory extends AbstractFactory { $provider = 'security.authentication.provider.dao.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.dao')) ->replaceArgument(0, new Reference($userProviderId)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->replaceArgument(2, $id) @@ -82,7 +82,7 @@ class JsonLoginFactory extends AbstractFactory protected function createListener($container, $id, $config, $userProvider) { $listenerId = $this->getListenerId(); - $listener = new DefinitionDecorator($listenerId); + $listener = new ChildDefinition($listenerId); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config))); $listener->replaceArgument(4, new Reference($this->createAuthenticationFailureHandler($container, $id, $config))); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php index fc008a9fbd..a81cc12fe5 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -34,7 +34,7 @@ class RememberMeFactory implements SecurityFactoryInterface // authentication provider $authProviderId = 'security.authentication.provider.rememberme.'.$id; $container - ->setDefinition($authProviderId, new DefinitionDecorator('security.authentication.provider.rememberme')) + ->setDefinition($authProviderId, new ChildDefinition('security.authentication.provider.rememberme')) ->replaceArgument(0, new Reference('security.user_checker.'.$id)) ->addArgument($config['secret']) ->addArgument($id) @@ -56,7 +56,7 @@ class RememberMeFactory implements SecurityFactoryInterface ; } - $rememberMeServices = $container->setDefinition($rememberMeServicesId, new DefinitionDecorator($templateId)); + $rememberMeServices = $container->setDefinition($rememberMeServicesId, new ChildDefinition($templateId)); $rememberMeServices->replaceArgument(1, $config['secret']); $rememberMeServices->replaceArgument(2, $id); @@ -101,7 +101,7 @@ class RememberMeFactory implements SecurityFactoryInterface // remember-me listener $listenerId = 'security.authentication.listener.rememberme.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.rememberme')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.rememberme')); $listener->replaceArgument(1, new Reference($rememberMeServicesId)); $listener->replaceArgument(5, $config['catch_exceptions']); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php index cf2e2ed71b..5e0c9d716b 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -28,14 +28,14 @@ class RemoteUserFactory implements SecurityFactoryInterface { $providerId = 'security.authentication.provider.pre_authenticated.'.$id; $container - ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.pre_authenticated')) + ->setDefinition($providerId, new ChildDefinition('security.authentication.provider.pre_authenticated')) ->replaceArgument(0, new Reference($userProvider)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->addArgument($id) ; $listenerId = 'security.authentication.listener.remote_user.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.remote_user')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.remote_user')); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, $config['user']); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimpleFormFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimpleFormFactory.php index 9da6601ff5..ad70f9f5ea 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimpleFormFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimpleFormFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -51,7 +51,7 @@ class SimpleFormFactory extends FormLoginFactory { $provider = 'security.authentication.provider.simple_form.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.simple')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.simple')) ->replaceArgument(0, new Reference($config['authenticator'])) ->replaceArgument(1, new Reference($userProviderId)) ->replaceArgument(2, $id) @@ -65,7 +65,7 @@ class SimpleFormFactory extends FormLoginFactory $listenerId = parent::createListener($container, $id, $config, $userProvider); $simpleAuthHandlerId = 'security.authentication.simple_success_failure_handler.'.$id; - $simpleAuthHandler = $container->setDefinition($simpleAuthHandlerId, new DefinitionDecorator('security.authentication.simple_success_failure_handler')); + $simpleAuthHandler = $container->setDefinition($simpleAuthHandlerId, new ChildDefinition('security.authentication.simple_success_failure_handler')); $simpleAuthHandler->replaceArgument(0, new Reference($config['authenticator'])); $simpleAuthHandler->replaceArgument(1, new Reference($this->getSuccessHandlerId($id))); $simpleAuthHandler->replaceArgument(2, new Reference($this->getFailureHandlerId($id))); @@ -82,7 +82,7 @@ class SimpleFormFactory extends FormLoginFactory { $entryPointId = 'security.authentication.form_entry_point.'.$id; $container - ->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.form_entry_point')) + ->setDefinition($entryPointId, new ChildDefinition('security.authentication.form_entry_point')) ->addArgument(new Reference('security.http_utils')) ->addArgument($config['login_path']) ->addArgument($config['use_forward']) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimplePreAuthenticationFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimplePreAuthenticationFactory.php index 27d8c5f050..b1304a55b3 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimplePreAuthenticationFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SimplePreAuthenticationFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -45,7 +45,7 @@ class SimplePreAuthenticationFactory implements SecurityFactoryInterface { $provider = 'security.authentication.provider.simple_preauth.'.$id; $container - ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.simple')) + ->setDefinition($provider, new ChildDefinition('security.authentication.provider.simple')) ->replaceArgument(0, new Reference($config['authenticator'])) ->replaceArgument(1, new Reference($userProvider)) ->replaceArgument(2, $id) @@ -53,7 +53,7 @@ class SimplePreAuthenticationFactory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.simple_preauth.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.simple_preauth')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.simple_preauth')); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, new Reference($config['authenticator'])); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php index 0467ef2ba2..39a1016b34 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -27,7 +27,7 @@ class X509Factory implements SecurityFactoryInterface { $providerId = 'security.authentication.provider.pre_authenticated.'.$id; $container - ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.pre_authenticated')) + ->setDefinition($providerId, new ChildDefinition('security.authentication.provider.pre_authenticated')) ->replaceArgument(0, new Reference($userProvider)) ->replaceArgument(1, new Reference('security.user_checker.'.$id)) ->addArgument($id) @@ -35,7 +35,7 @@ class X509Factory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.x509.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.x509')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.x509')); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, $config['user']); $listener->replaceArgument(4, $config['credentials']); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php index b184385f22..b3752f4b18 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -26,13 +26,13 @@ class InMemoryFactory implements UserProviderFactoryInterface { public function create(ContainerBuilder $container, $id, $config) { - $definition = $container->setDefinition($id, new DefinitionDecorator('security.user.provider.in_memory')); + $definition = $container->setDefinition($id, new ChildDefinition('security.user.provider.in_memory')); foreach ($config['users'] as $username => $user) { $userId = $id.'_'.$username; $container - ->setDefinition($userId, new DefinitionDecorator('security.user.provider.in_memory.user')) + ->setDefinition($userId, new ChildDefinition('security.user.provider.in_memory.user')) ->setArguments(array($username, (string) $user['password'], $user['roles'])) ; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/LdapFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/LdapFactory.php index ecaf35364d..f213a32f8b 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/LdapFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/LdapFactory.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider; use Symfony\Component\Config\Definition\Builder\NodeDefinition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -27,7 +27,7 @@ class LdapFactory implements UserProviderFactoryInterface public function create(ContainerBuilder $container, $id, $config) { $container - ->setDefinition($id, new DefinitionDecorator('security.user.provider.ldap')) + ->setDefinition($id, new ChildDefinition('security.user.provider.ldap')) ->replaceArgument(0, new Reference($config['service'])) ->replaceArgument(1, $config['base_dn']) ->replaceArgument(2, $config['search_dn']) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index faa28fc175..1bdd16d0d8 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -14,8 +14,8 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -242,7 +242,7 @@ class SecurityExtension extends Extension list($matcher, $listeners, $exceptionListener) = $this->createFirewall($container, $name, $firewall, $authenticationProviders, $providerIds, $configId); $contextId = 'security.firewall.map.context.'.$name; - $context = $container->setDefinition($contextId, new DefinitionDecorator('security.firewall.context')); + $context = $container->setDefinition($contextId, new ChildDefinition('security.firewall.context')); $context ->replaceArgument(0, $listeners) ->replaceArgument(1, $exceptionListener) @@ -265,7 +265,7 @@ class SecurityExtension extends Extension private function createFirewall(ContainerBuilder $container, $id, $firewall, &$authenticationProviders, $providerIds, $configId) { - $config = $container->setDefinition($configId, new DefinitionDecorator('security.firewall.config')); + $config = $container->setDefinition($configId, new ChildDefinition('security.firewall.config')); $config->replaceArgument(0, $id); $config->replaceArgument(1, $firewall['user_checker']); @@ -323,7 +323,7 @@ class SecurityExtension extends Extension if (isset($firewall['logout'])) { $listenerKeys[] = 'logout'; $listenerId = 'security.logout_listener.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.logout_listener')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.logout_listener')); $listener->replaceArgument(3, array( 'csrf_parameter' => $firewall['logout']['csrf_parameter'], 'csrf_token_id' => $firewall['logout']['csrf_token_id'], @@ -336,7 +336,7 @@ class SecurityExtension extends Extension $logoutSuccessHandlerId = $firewall['logout']['success_handler']; } else { $logoutSuccessHandlerId = 'security.logout.success_handler.'.$id; - $logoutSuccessHandler = $container->setDefinition($logoutSuccessHandlerId, new DefinitionDecorator('security.logout.success_handler')); + $logoutSuccessHandler = $container->setDefinition($logoutSuccessHandlerId, new ChildDefinition('security.logout.success_handler')); $logoutSuccessHandler->replaceArgument(1, $firewall['logout']['target']); } $listener->replaceArgument(2, new Reference($logoutSuccessHandlerId)); @@ -354,7 +354,7 @@ class SecurityExtension extends Extension // add cookie logout handler if (count($firewall['logout']['delete_cookies']) > 0) { $cookieHandlerId = 'security.logout.handler.cookie_clearing.'.$id; - $cookieHandler = $container->setDefinition($cookieHandlerId, new DefinitionDecorator('security.logout.handler.cookie_clearing')); + $cookieHandler = $container->setDefinition($cookieHandlerId, new ChildDefinition('security.logout.handler.cookie_clearing')); $cookieHandler->addArgument($firewall['logout']['delete_cookies']); $listener->addMethodCall('addHandler', array(new Reference($cookieHandlerId))); @@ -430,7 +430,7 @@ class SecurityExtension extends Extension } $listenerId = 'security.context_listener.'.count($this->contextListeners); - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.context_listener')); + $listener = $container->setDefinition($listenerId, new ChildDefinition('security.context_listener')); $listener->replaceArgument(2, $contextKey); return $this->contextListeners[$contextKey] = $listenerId; @@ -461,7 +461,7 @@ class SecurityExtension extends Extension if (isset($firewall['anonymous'])) { $listenerId = 'security.authentication.listener.anonymous.'.$id; $container - ->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.anonymous')) + ->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.anonymous')) ->replaceArgument(1, $firewall['anonymous']['secret']) ; @@ -469,7 +469,7 @@ class SecurityExtension extends Extension $providerId = 'security.authentication.provider.anonymous.'.$id; $container - ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.anonymous')) + ->setDefinition($providerId, new ChildDefinition('security.authentication.provider.anonymous')) ->replaceArgument(0, $firewall['anonymous']['secret']) ; @@ -582,7 +582,7 @@ class SecurityExtension extends Extension } $container - ->setDefinition($name, new DefinitionDecorator('security.user.provider.chain')) + ->setDefinition($name, new ChildDefinition('security.user.provider.chain')) ->addArgument($providers); return $name; @@ -599,7 +599,7 @@ class SecurityExtension extends Extension private function createExceptionListener($container, $config, $id, $defaultEntryPoint, $stateless) { $exceptionListenerId = 'security.exception_listener.'.$id; - $listener = $container->setDefinition($exceptionListenerId, new DefinitionDecorator('security.exception_listener')); + $listener = $container->setDefinition($exceptionListenerId, new ChildDefinition('security.exception_listener')); $listener->replaceArgument(3, $id); $listener->replaceArgument(4, null === $defaultEntryPoint ? null : new Reference($defaultEntryPoint)); $listener->replaceArgument(8, $stateless); @@ -619,7 +619,7 @@ class SecurityExtension extends Extension $userProvider = isset($config['provider']) ? $this->getUserProviderId($config['provider']) : $defaultProvider; $switchUserListenerId = 'security.authentication.switchuser_listener.'.$id; - $listener = $container->setDefinition($switchUserListenerId, new DefinitionDecorator('security.authentication.switchuser_listener')); + $listener = $container->setDefinition($switchUserListenerId, new ChildDefinition('security.authentication.switchuser_listener')); $listener->replaceArgument(1, new Reference($userProvider)); $listener->replaceArgument(2, new Reference('security.user_checker.'.$id)); $listener->replaceArgument(3, $id); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php index db4c51c5f0..56fcd404cd 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php @@ -54,6 +54,9 @@ class SetAclCommandTest extends WebTestCase $this->deleteTmpDir('Acl'); } + /** + * @group legacy + */ public function testSetAclUser() { $objectId = 1; diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index d846404f2c..4d75cfd7cd 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -18,6 +18,7 @@ "require": { "php": ">=5.5.9", "symfony/security": "~3.3", + "symfony/dependency-injection": "~3.3", "symfony/http-kernel": "~3.2", "symfony/polyfill-php70": "~1.0" }, diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 43f445736f..05d5ad3d07 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +3.3.0 +----- + + * deprecated the `DefinitionDecorator` class in favor of `ChildDefinition` + 3.2.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/ChildDefinition.php b/src/Symfony/Component/DependencyInjection/ChildDefinition.php new file mode 100644 index 0000000000..f10bcddfc0 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/ChildDefinition.php @@ -0,0 +1,199 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection; + +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; + +/** + * This definition extends another definition. + * + * @author Johannes M. Schmitt + */ +class ChildDefinition extends Definition +{ + private $parent; + private $changes = array(); + + /** + * @param string $parent The id of Definition instance to decorate + */ + public function __construct($parent) + { + parent::__construct(); + + $this->parent = $parent; + } + + /** + * Returns the Definition being decorated. + * + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Returns all changes tracked for the Definition object. + * + * @return array An array of changes for this Definition + */ + public function getChanges() + { + return $this->changes; + } + + /** + * {@inheritdoc} + */ + public function setClass($class) + { + $this->changes['class'] = true; + + return parent::setClass($class); + } + + /** + * {@inheritdoc} + */ + public function setFactory($callable) + { + $this->changes['factory'] = true; + + return parent::setFactory($callable); + } + + /** + * {@inheritdoc} + */ + public function setConfigurator($callable) + { + $this->changes['configurator'] = true; + + return parent::setConfigurator($callable); + } + + /** + * {@inheritdoc} + */ + public function setFile($file) + { + $this->changes['file'] = true; + + return parent::setFile($file); + } + + /** + * {@inheritdoc} + */ + public function setPublic($boolean) + { + $this->changes['public'] = true; + + return parent::setPublic($boolean); + } + + /** + * {@inheritdoc} + */ + public function setLazy($boolean) + { + $this->changes['lazy'] = true; + + return parent::setLazy($boolean); + } + + /** + * {@inheritdoc} + */ + public function setDecoratedService($id, $renamedId = null, $priority = 0) + { + $this->changes['decorated_service'] = true; + + return parent::setDecoratedService($id, $renamedId, $priority); + } + + /** + * {@inheritdoc} + */ + public function setDeprecated($boolean = true, $template = null) + { + $this->changes['deprecated'] = true; + + return parent::setDeprecated($boolean, $template); + } + + /** + * {@inheritdoc} + */ + public function setAutowired($autowired) + { + $this->changes['autowire'] = true; + + return parent::setAutowired($autowired); + } + + /** + * Gets an argument to pass to the service constructor/factory method. + * + * If replaceArgument() has been used to replace an argument, this method + * will return the replacement value. + * + * @param int $index + * + * @return mixed The argument value + * + * @throws OutOfBoundsException When the argument does not exist + */ + public function getArgument($index) + { + if (array_key_exists('index_'.$index, $this->arguments)) { + return $this->arguments['index_'.$index]; + } + + $lastIndex = count(array_filter(array_keys($this->arguments), 'is_int')) - 1; + + if ($index < 0 || $index > $lastIndex) { + throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, $lastIndex)); + } + + return $this->arguments[$index]; + } + + /** + * You should always use this method when overwriting existing arguments + * of the parent definition. + * + * If you directly call setArguments() keep in mind that you must follow + * certain conventions when you want to overwrite the arguments of the + * parent definition, otherwise your arguments will only be appended. + * + * @param int $index + * @param mixed $value + * + * @return self the current instance + * + * @throws InvalidArgumentException when $index isn't an integer + */ + public function replaceArgument($index, $value) + { + if (!is_int($index)) { + throw new InvalidArgumentException('$index must be an integer.'); + } + + $this->arguments['index_'.$index] = $value; + + return $this; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php index a755fd61e1..5603d6274b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php @@ -11,14 +11,14 @@ namespace Symfony\Component\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\ExceptionInterface; use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** - * This replaces all DefinitionDecorator instances with their equivalent fully + * This replaces all ChildDefinition instances with their equivalent fully * merged Definition instance. * * @author Johannes M. Schmitt @@ -31,7 +31,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface private $currentId; /** - * Process the ContainerBuilder to replace DefinitionDecorator instances with their real Definition instances. + * Process the ContainerBuilder to replace ChildDefinition instances with their real Definition instances. * * @param ContainerBuilder $container */ @@ -64,7 +64,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface if (is_array($argument)) { $arguments[$k] = $this->resolveArguments($container, $argument); } elseif ($argument instanceof Definition) { - if ($argument instanceof DefinitionDecorator) { + if ($argument instanceof ChildDefinition) { $arguments[$k] = $argument = $this->resolveDefinition($container, $argument); if ($isRoot) { $container->setDefinition($k, $argument); @@ -88,14 +88,14 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface /** * Resolves the definition. * - * @param ContainerBuilder $container The ContainerBuilder - * @param DefinitionDecorator $definition + * @param ContainerBuilder $container The ContainerBuilder + * @param ChildDefinition $definition * * @return Definition * * @throws \RuntimeException When the definition is invalid */ - private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition) + private function resolveDefinition(ContainerBuilder $container, ChildDefinition $definition) { try { return $this->doResolveDefinition($container, $definition); @@ -108,14 +108,14 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface } } - private function doResolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition) + private function doResolveDefinition(ContainerBuilder $container, ChildDefinition $definition) { if (!$container->has($parent = $definition->getParent())) { throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent)); } $parentDef = $container->findDefinition($parent); - if ($parentDef instanceof DefinitionDecorator) { + if ($parentDef instanceof ChildDefinition) { $id = $this->currentId; $this->currentId = $parent; $parentDef = $this->resolveDefinition($container, $parentDef); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index e57d410034..42e70c1e23 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -851,7 +851,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface */ private function createService(Definition $definition, $id, $tryProxy = true) { - if ($definition instanceof DefinitionDecorator) { + if ($definition instanceof ChildDefinition) { throw new RuntimeException(sprintf('Constructing service "%s" from a parent definition is not supported at build time.', $id)); } diff --git a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php index f17657a3a1..00e31ff3d0 100644 --- a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php +++ b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php @@ -11,189 +11,15 @@ namespace Symfony\Component\DependencyInjection; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; +@trigger_error('The '.__NAMESPACE__.'\DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead.', E_USER_DEPRECATED); /** * This definition decorates another definition. * * @author Johannes M. Schmitt + * + * @deprecated The DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead. */ -class DefinitionDecorator extends Definition +class DefinitionDecorator extends ChildDefinition { - private $parent; - private $changes = array(); - - /** - * @param string $parent The id of Definition instance to decorate - */ - public function __construct($parent) - { - parent::__construct(); - - $this->parent = $parent; - } - - /** - * Returns the Definition being decorated. - * - * @return string - */ - public function getParent() - { - return $this->parent; - } - - /** - * Returns all changes tracked for the Definition object. - * - * @return array An array of changes for this Definition - */ - public function getChanges() - { - return $this->changes; - } - - /** - * {@inheritdoc} - */ - public function setClass($class) - { - $this->changes['class'] = true; - - return parent::setClass($class); - } - - /** - * {@inheritdoc} - */ - public function setFactory($callable) - { - $this->changes['factory'] = true; - - return parent::setFactory($callable); - } - - /** - * {@inheritdoc} - */ - public function setConfigurator($callable) - { - $this->changes['configurator'] = true; - - return parent::setConfigurator($callable); - } - - /** - * {@inheritdoc} - */ - public function setFile($file) - { - $this->changes['file'] = true; - - return parent::setFile($file); - } - - /** - * {@inheritdoc} - */ - public function setPublic($boolean) - { - $this->changes['public'] = true; - - return parent::setPublic($boolean); - } - - /** - * {@inheritdoc} - */ - public function setLazy($boolean) - { - $this->changes['lazy'] = true; - - return parent::setLazy($boolean); - } - - /** - * {@inheritdoc} - */ - public function setDecoratedService($id, $renamedId = null, $priority = 0) - { - $this->changes['decorated_service'] = true; - - return parent::setDecoratedService($id, $renamedId, $priority); - } - - /** - * {@inheritdoc} - */ - public function setDeprecated($boolean = true, $template = null) - { - $this->changes['deprecated'] = true; - - return parent::setDeprecated($boolean, $template); - } - - /** - * {@inheritdoc} - */ - public function setAutowired($autowired) - { - $this->changes['autowire'] = true; - - return parent::setAutowired($autowired); - } - - /** - * Gets an argument to pass to the service constructor/factory method. - * - * If replaceArgument() has been used to replace an argument, this method - * will return the replacement value. - * - * @param int $index - * - * @return mixed The argument value - * - * @throws OutOfBoundsException When the argument does not exist - */ - public function getArgument($index) - { - if (array_key_exists('index_'.$index, $this->arguments)) { - return $this->arguments['index_'.$index]; - } - - $lastIndex = count(array_filter(array_keys($this->arguments), 'is_int')) - 1; - - if ($index < 0 || $index > $lastIndex) { - throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, $lastIndex)); - } - - return $this->arguments[$index]; - } - - /** - * You should always use this method when overwriting existing arguments - * of the parent definition. - * - * If you directly call setArguments() keep in mind that you must follow - * certain conventions when you want to overwrite the arguments of the - * parent definition, otherwise your arguments will only be appended. - * - * @param int $index - * @param mixed $value - * - * @return DefinitionDecorator the current instance - * - * @throws InvalidArgumentException when $index isn't an integer - */ - public function replaceArgument($index, $value) - { - if (!is_int($index)) { - throw new InvalidArgumentException('$index must be an integer.'); - } - - $this->arguments['index_'.$index] = $value; - - return $this; - } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 01911625f8..53013e2512 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -13,10 +13,10 @@ namespace Symfony\Component\DependencyInjection\Loader; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Util\XmlUtils; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; @@ -145,7 +145,7 @@ class XmlFileLoader extends FileLoader } if ($parent = $service->getAttribute('parent')) { - $definition = new DefinitionDecorator($parent); + $definition = new ChildDefinition($parent); } else { $definition = new Definition(); } @@ -346,7 +346,7 @@ class XmlFileLoader extends FileLoader $arg->setAttribute('key', $arg->getAttribute('name')); } - // this is used by DefinitionDecorator to overwrite a specific + // this is used by ChildDefinition to overwrite a specific // argument of the parent definition if ($arg->hasAttribute('index')) { $key = 'index_'.$arg->getAttribute('index'); diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index cffe00c750..02385c06bd 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -11,8 +11,8 @@ namespace Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -189,7 +189,7 @@ class YamlFileLoader extends FileLoader } if (isset($service['parent'])) { - $definition = new DefinitionDecorator($service['parent']); + $definition = new ChildDefinition($service['parent']); } else { $definition = new Definition(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php new file mode 100644 index 0000000000..8f89e3b626 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php @@ -0,0 +1,128 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests; + +use Symfony\Component\DependencyInjection\ChildDefinition; + +class ChildDefinitionTest extends \PHPUnit_Framework_TestCase +{ + public function testConstructor() + { + $def = new ChildDefinition('foo'); + + $this->assertSame('foo', $def->getParent()); + $this->assertSame(array(), $def->getChanges()); + } + + /** + * @dataProvider getPropertyTests + */ + public function testSetProperty($property, $changeKey) + { + $def = new ChildDefinition('foo'); + + $getter = 'get'.ucfirst($property); + $setter = 'set'.ucfirst($property); + + $this->assertNull($def->$getter()); + $this->assertSame($def, $def->$setter('foo')); + $this->assertSame('foo', $def->$getter()); + $this->assertSame(array($changeKey => true), $def->getChanges()); + } + + public function getPropertyTests() + { + return array( + array('class', 'class'), + array('factory', 'factory'), + array('configurator', 'configurator'), + array('file', 'file'), + ); + } + + public function testSetPublic() + { + $def = new ChildDefinition('foo'); + + $this->assertTrue($def->isPublic()); + $this->assertSame($def, $def->setPublic(false)); + $this->assertFalse($def->isPublic()); + $this->assertSame(array('public' => true), $def->getChanges()); + } + + public function testSetLazy() + { + $def = new ChildDefinition('foo'); + + $this->assertFalse($def->isLazy()); + $this->assertSame($def, $def->setLazy(false)); + $this->assertFalse($def->isLazy()); + $this->assertSame(array('lazy' => true), $def->getChanges()); + } + + public function testSetAutowired() + { + $def = new ChildDefinition('foo'); + + $this->assertFalse($def->isAutowired()); + $this->assertSame($def, $def->setAutowired(false)); + $this->assertFalse($def->isAutowired()); + $this->assertSame(array('autowire' => true), $def->getChanges()); + } + + public function testSetArgument() + { + $def = new ChildDefinition('foo'); + + $this->assertSame(array(), $def->getArguments()); + $this->assertSame($def, $def->replaceArgument(0, 'foo')); + $this->assertSame(array('index_0' => 'foo'), $def->getArguments()); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testReplaceArgumentShouldRequireIntegerIndex() + { + $def = new ChildDefinition('foo'); + + $def->replaceArgument('0', 'foo'); + } + + public function testReplaceArgument() + { + $def = new ChildDefinition('foo'); + + $def->setArguments(array(0 => 'foo', 1 => 'bar')); + $this->assertSame('foo', $def->getArgument(0)); + $this->assertSame('bar', $def->getArgument(1)); + + $this->assertSame($def, $def->replaceArgument(1, 'baz')); + $this->assertSame('foo', $def->getArgument(0)); + $this->assertSame('baz', $def->getArgument(1)); + + $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments()); + } + + /** + * @expectedException \OutOfBoundsException + */ + public function testGetArgumentShouldCheckBounds() + { + $def = new ChildDefinition('foo'); + + $def->setArguments(array(0 => 'foo')); + $def->replaceArgument(0, 'foo'); + + $def->getArgument(1); + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php index 3ca0df4a77..f1141f6e61 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php @@ -11,7 +11,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -21,7 +21,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase { $container = new ContainerBuilder(); $container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo'); - $container->setDefinition('child', new DefinitionDecorator('parent')) + $container->setDefinition('child', new ChildDefinition('parent')) ->replaceArgument(0, 'a') ->setProperty('foo', 'bar') ->setClass('bar') @@ -30,7 +30,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $this->process($container); $def = $container->getDefinition('child'); - $this->assertNotInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $def); + $this->assertNotInstanceOf(ChildDefinition::class, $def); $this->assertEquals('bar', $def->getClass()); $this->assertEquals(array('a', 'b'), $def->getArguments()); $this->assertEquals(array('foo' => 'bar'), $def->getProperties()); @@ -46,7 +46,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ->addMethodCall('bar', array('foo')) ; @@ -69,7 +69,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ; $this->process($container); @@ -88,7 +88,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ; $this->process($container); @@ -107,7 +107,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ; $this->process($container); @@ -126,7 +126,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ; $this->process($container); @@ -144,7 +144,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ->setShared(false) ; @@ -164,12 +164,12 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child2', new DefinitionDecorator('child1')) + ->setDefinition('child2', new ChildDefinition('child1')) ->replaceArgument(1, 'b') ; $container - ->setDefinition('child1', new DefinitionDecorator('parent')) + ->setDefinition('child1', new ChildDefinition('parent')) ->replaceArgument(0, 'a') ; @@ -186,7 +186,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container->register('parent', 'stdClass'); - $container->setDefinition('child1', new DefinitionDecorator('parent')) + $container->setDefinition('child1', new ChildDefinition('parent')) ->setLazy(true) ; @@ -203,7 +203,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ->setLazy(true) ; - $container->setDefinition('child1', new DefinitionDecorator('parent')); + $container->setDefinition('child1', new ChildDefinition('parent')); $this->process($container); @@ -216,7 +216,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container->register('parent', 'stdClass'); - $container->setDefinition('child1', new DefinitionDecorator('parent')) + $container->setDefinition('child1', new ChildDefinition('parent')) ->setAutowired(true) ; @@ -233,7 +233,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ->setAutowired(true) ; - $container->setDefinition('child1', new DefinitionDecorator('parent')); + $container->setDefinition('child1', new ChildDefinition('parent')); $this->process($container); @@ -246,11 +246,11 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container->register('parent', 'parentClass'); $container->register('sibling', 'siblingClass') - ->setConfigurator(new DefinitionDecorator('parent'), 'foo') - ->setFactory(array(new DefinitionDecorator('parent'), 'foo')) - ->addArgument(new DefinitionDecorator('parent')) - ->setProperty('prop', new DefinitionDecorator('parent')) - ->addMethodCall('meth', array(new DefinitionDecorator('parent'))) + ->setConfigurator(new ChildDefinition('parent'), 'foo') + ->setFactory(array(new ChildDefinition('parent'), 'foo')) + ->addArgument(new ChildDefinition('parent')) + ->setProperty('prop', new ChildDefinition('parent')) + ->addMethodCall('meth', array(new ChildDefinition('parent'))) ; $this->process($container); @@ -282,7 +282,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container->register('parent', 'stdClass'); - $container->setDefinition('child1', new DefinitionDecorator('parent')) + $container->setDefinition('child1', new ChildDefinition('parent')) ->setDecoratedService('foo', 'foo_inner', 5) ; @@ -298,7 +298,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ->setDeprecated(true) ; - $container->setDefinition('decorated_deprecated_parent', new DefinitionDecorator('deprecated_parent')); + $container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent')); $this->process($container); @@ -312,7 +312,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ->setDeprecated(true) ; - $container->setDefinition('decorated_deprecated_parent', new DefinitionDecorator('deprecated_parent')) + $container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent')) ->setDeprecated(false) ; @@ -331,7 +331,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase ; $container - ->setDefinition('child', new DefinitionDecorator('parent')) + ->setDefinition('child', new ChildDefinition('parent')) ->addAutowiringType('Bar') ; @@ -350,7 +350,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container->register('parent', 'ParentClass'); $container->setAlias('parent_alias', 'parent'); - $container->setDefinition('child', new DefinitionDecorator('parent_alias')); + $container->setDefinition('child', new ChildDefinition('parent_alias')); $this->process($container); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 3808e990e2..a0caf0fb2d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -16,11 +16,11 @@ require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; @@ -443,8 +443,8 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase { $builder = new ContainerBuilder(); $builder->setDefinition('grandpa', new Definition('stdClass')); - $builder->setDefinition('parent', new DefinitionDecorator('grandpa')); - $builder->setDefinition('foo', new DefinitionDecorator('parent')); + $builder->setDefinition('parent', new ChildDefinition('grandpa')); + $builder->setDefinition('foo', new ChildDefinition('parent')); $builder->get('foo'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php index c42cf2350d..0563bc71cb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php @@ -13,6 +13,9 @@ namespace Symfony\Component\DependencyInjection\Tests; use Symfony\Component\DependencyInjection\DefinitionDecorator; +/** + * @group legacy + */ class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase { public function testConstructor()