From 7a7ff24a432d7fe113983fe8ebbbdc40e35e676c Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 20 Feb 2017 19:49:52 +0100 Subject: [PATCH] Move PropertyInfoPass to the PropertyInfo component --- UPGRADE-3.3.md | 4 + UPGRADE-4.0.md | 3 + .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Compiler/PropertyInfoPass.php | 36 ++------- .../FrameworkBundle/FrameworkBundle.php | 4 +- .../Compiler/PropertyInfoPassTest.php | 3 + .../DependencyInjection/CHANGELOG.md | 7 ++ .../DependencyInjection/PropertyInfoPass.php | 66 ++++++++++++++++ .../PropertyInfoPassTest.php | 76 +++++++++++++++++++ .../Component/PropertyInfo/composer.json | 4 +- 10 files changed, 171 insertions(+), 33 deletions(-) create mode 100644 src/Symfony/Component/PropertyInfo/DependencyInjection/CHANGELOG.md create mode 100644 src/Symfony/Component/PropertyInfo/DependencyInjection/PropertyInfoPass.php create mode 100644 src/Symfony/Component/PropertyInfo/Tests/DependencyInjection/PropertyInfoPassTest.php diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 398d16f01d..65e7e0e0d8 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -139,6 +139,10 @@ FrameworkBundle deprecated and will be removed in 4.0. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead. + * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass` class has been + deprecated and will be removed in 4.0. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` + class instead. + HttpKernel ----------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 5e9f233ff4..daac2d04c5 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -198,6 +198,9 @@ FrameworkBundle * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead. + * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass` class has been + removed. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` + class instead. HttpFoundation --------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 0f0724c77e..d91ae4babb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -19,6 +19,7 @@ CHANGELOG * Deprecated `TestSessionListener` * Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`. Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead. + * Deprecated `PropertyInfoPass`, use `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` instead 3.2.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php index d98709b40d..3c73f9bf49 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php @@ -11,41 +11,17 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Argument\IteratorArgument; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; -use Symfony\Component\DependencyInjection\ContainerBuilder; +@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass instead.', PropertyInfoPass::class), E_USER_DEPRECATED); + +use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass as BasePropertyInfoPass; /** * Adds extractors to the property_info service. * * @author Kévin Dunglas + * + * @deprecated since version 3.3, to be removed in 4.0. Use {@link BasePropertyInfoPass instead}. */ -class PropertyInfoPass implements CompilerPassInterface +class PropertyInfoPass extends BasePropertyInfoPass { - use PriorityTaggedServiceTrait; - - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition('property_info')) { - return; - } - - $definition = $container->getDefinition('property_info'); - - $listExtractors = $this->findAndSortTaggedServices('property_info.list_extractor', $container); - $definition->replaceArgument(0, new IteratorArgument($listExtractors)); - - $typeExtractors = $this->findAndSortTaggedServices('property_info.type_extractor', $container); - $definition->replaceArgument(1, new IteratorArgument($typeExtractors)); - - $descriptionExtractors = $this->findAndSortTaggedServices('property_info.description_extractor', $container); - $definition->replaceArgument(2, new IteratorArgument($descriptionExtractors)); - - $accessExtractors = $this->findAndSortTaggedServices('property_info.access_extractor', $container); - $definition->replaceArgument(3, new IteratorArgument($accessExtractors)); - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 7f610483b7..0274a5db0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -19,7 +19,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPa use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass; @@ -37,6 +36,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass; use Symfony\Component\Config\DependencyInjection\ConfigCachePass; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; +use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass; use Symfony\Component\Serializer\DependencyInjection\SerializerPass; use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -95,7 +95,7 @@ class FrameworkBundle extends Bundle $container->addCompilerPass(new TranslationDumperPass()); $container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING); $this->addCompilerPassIfExists($container, SerializerPass::class); - $container->addCompilerPass(new PropertyInfoPass()); + $this->addCompilerPassIfExists($container, PropertyInfoPass::class); $container->addCompilerPass(new DataCollectorTranslatorPass()); $container->addCompilerPass(new ControllerArgumentValueResolverPass()); $container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php index 90f713fb56..0bfee565f5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php @@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass; use Symfony\Component\DependencyInjection\Reference; +/** + * @group legacy + */ class PropertyInfoPassTest extends TestCase { public function testServicesAreOrderedAccordingToPriority() diff --git a/src/Symfony/Component/PropertyInfo/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/PropertyInfo/DependencyInjection/CHANGELOG.md new file mode 100644 index 0000000000..4e98c95e27 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/DependencyInjection/CHANGELOG.md @@ -0,0 +1,7 @@ +CHANGELOG +========= + +3.3.0 +----- + +* Added `PropertyInfoPass` diff --git a/src/Symfony/Component/PropertyInfo/DependencyInjection/PropertyInfoPass.php b/src/Symfony/Component/PropertyInfo/DependencyInjection/PropertyInfoPass.php new file mode 100644 index 0000000000..c4bc893f72 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/DependencyInjection/PropertyInfoPass.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\DependencyInjection; + +use Symfony\Component\DependencyInjection\Argument\IteratorArgument; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Adds extractors to the property_info service. + * + * @author Kévin Dunglas + */ +class PropertyInfoPass implements CompilerPassInterface +{ + use PriorityTaggedServiceTrait; + + private $propertyInfoService; + private $listExtractorTag; + private $typeExtractorTag; + private $descriptionExtractorTag; + private $accessExtractorTag; + + public function __construct($propertyInfoService = 'property_info', $listExtractorTag = 'property_info.list_extractor', $typeExtractorTag = 'property_info.type_extractor', $descriptionExtractorTag = 'property_info.description_extractor', $accessExtractorTag = 'property_info.access_extractor') + { + $this->propertyInfoService = $propertyInfoService; + $this->listExtractorTag = $listExtractorTag; + $this->typeExtractorTag = $typeExtractorTag; + $this->descriptionExtractorTag = $descriptionExtractorTag; + $this->accessExtractorTag = $accessExtractorTag; + } + + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition($this->propertyInfoService)) { + return; + } + + $definition = $container->getDefinition($this->propertyInfoService); + + $listExtractors = $this->findAndSortTaggedServices($this->listExtractorTag, $container); + $definition->replaceArgument(0, new IteratorArgument($listExtractors)); + + $typeExtractors = $this->findAndSortTaggedServices($this->typeExtractorTag, $container); + $definition->replaceArgument(1, new IteratorArgument($typeExtractors)); + + $descriptionExtractors = $this->findAndSortTaggedServices($this->descriptionExtractorTag, $container); + $definition->replaceArgument(2, new IteratorArgument($descriptionExtractors)); + + $accessExtractors = $this->findAndSortTaggedServices($this->accessExtractorTag, $container); + $definition->replaceArgument(3, new IteratorArgument($accessExtractors)); + } +} diff --git a/src/Symfony/Component/PropertyInfo/Tests/DependencyInjection/PropertyInfoPassTest.php b/src/Symfony/Component/PropertyInfo/Tests/DependencyInjection/PropertyInfoPassTest.php new file mode 100644 index 0000000000..065f8afc88 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/DependencyInjection/PropertyInfoPassTest.php @@ -0,0 +1,76 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\Tests\DependencyInjection; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass; + +class PropertyInfoPassTest extends TestCase +{ + public function testServicesAreOrderedAccordingToPriority() + { + $services = array( + 'n3' => array('tag' => array()), + 'n1' => array('tag' => array('priority' => 200)), + 'n2' => array('tag' => array('priority' => 100)), + ); + + $expected = array( + new Reference('n1'), + new Reference('n2'), + new Reference('n3'), + ); + + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock(); + + $container + ->expects($this->any()) + ->method('findTaggedServiceIds') + ->will($this->returnValue($services)); + + $propertyInfoPass = new PropertyInfoPass(); + + $method = new \ReflectionMethod( + 'Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass', + 'findAndSortTaggedServices' + ); + $method->setAccessible(true); + + $actual = $method->invoke($propertyInfoPass, 'tag', $container); + + $this->assertEquals($expected, $actual); + } + + public function testReturningEmptyArrayWhenNoService() + { + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock(); + + $container + ->expects($this->any()) + ->method('findTaggedServiceIds') + ->will($this->returnValue(array())) + ; + + $propertyInfoPass = new PropertyInfoPass(); + + $method = new \ReflectionMethod( + 'Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass', + 'findAndSortTaggedServices' + ); + $method->setAccessible(true); + + $actual = $method->invoke($propertyInfoPass, 'tag', $container); + + $this->assertEquals(array(), $actual); + } +} diff --git a/src/Symfony/Component/PropertyInfo/composer.json b/src/Symfony/Component/PropertyInfo/composer.json index c19743894a..8a7b33dbfd 100644 --- a/src/Symfony/Component/PropertyInfo/composer.json +++ b/src/Symfony/Component/PropertyInfo/composer.json @@ -29,12 +29,14 @@ "require-dev": { "symfony/serializer": "~2.8|~3.0", "symfony/cache": "~3.1", + "symfony/dependency-injection": "~3.3", "phpdocumentor/reflection-docblock": "^3.0", "doctrine/annotations": "~1.0" }, "conflict": { "phpdocumentor/reflection-docblock": "<3.0", - "phpdocumentor/type-resolver": "<0.2.0" + "phpdocumentor/type-resolver": "<0.2.0", + "symfony/dependency-injection": "<3.3" }, "suggest": { "psr/cache-implementation": "To cache results",