From 38523a9736dddc070cbb305aebeffaa7344a50a5 Mon Sep 17 00:00:00 2001 From: Guilhem N Date: Fri, 17 Feb 2017 19:42:42 +0100 Subject: [PATCH] [PropertyInfo] Use iterators for PropertyInfoExtractor --- .../Compiler/PropertyInfoPass.php | 9 ++--- .../Bundle/FrameworkBundle/composer.json | 5 +-- .../PropertyInfo/PropertyInfoExtractor.php | 33 +++++-------------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php index f05445f1a6276..d98709b40d56d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/PropertyInfoPass.php @@ -11,6 +11,7 @@ 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; @@ -36,15 +37,15 @@ public function process(ContainerBuilder $container) $definition = $container->getDefinition('property_info'); $listExtractors = $this->findAndSortTaggedServices('property_info.list_extractor', $container); - $definition->replaceArgument(0, $listExtractors); + $definition->replaceArgument(0, new IteratorArgument($listExtractors)); $typeExtractors = $this->findAndSortTaggedServices('property_info.type_extractor', $container); - $definition->replaceArgument(1, $typeExtractors); + $definition->replaceArgument(1, new IteratorArgument($typeExtractors)); $descriptionExtractors = $this->findAndSortTaggedServices('property_info.description_extractor', $container); - $definition->replaceArgument(2, $descriptionExtractors); + $definition->replaceArgument(2, new IteratorArgument($descriptionExtractors)); $accessExtractors = $this->findAndSortTaggedServices('property_info.access_extractor', $container); - $definition->replaceArgument(3, $accessExtractors); + $definition->replaceArgument(3, new IteratorArgument($accessExtractors)); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 1bc322ce98286..adfb80a404b6d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -51,7 +51,7 @@ "symfony/templating": "~2.8|~3.0", "symfony/validator": "~3.2", "symfony/yaml": "~3.2", - "symfony/property-info": "~3.1", + "symfony/property-info": "~3.3", "doctrine/annotations": "~1.0", "phpdocumentor/reflection-docblock": "^3.0", "twig/twig": "~1.26|~2.0", @@ -62,7 +62,8 @@ "phpdocumentor/type-resolver": "<0.2.0", "symfony/console": "<3.3", "symfony/serializer": "<3.3", - "symfony/form": "<3.3" + "symfony/form": "<3.3", + "symfony/property-info": "<3.3" }, "suggest": { "ext-apcu": "For best performance of the system caches", diff --git a/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php b/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php index 031c8ac05e26a..8c89489405919 100644 --- a/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php +++ b/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php @@ -18,33 +18,18 @@ */ class PropertyInfoExtractor implements PropertyInfoExtractorInterface { - /** - * @var PropertyListExtractorInterface[] - */ private $listExtractors; - - /** - * @var PropertyTypeExtractorInterface[] - */ private $typeExtractors; - - /** - * @var PropertyDescriptionExtractorInterface[] - */ private $descriptionExtractors; - - /** - * @var PropertyAccessExtractorInterface[] - */ private $accessExtractors; /** - * @param PropertyListExtractorInterface[] $listExtractors - * @param PropertyTypeExtractorInterface[] $typeExtractors - * @param PropertyDescriptionExtractorInterface[] $descriptionExtractors - * @param PropertyAccessExtractorInterface[] $accessExtractors + * @param iterable|PropertyListExtractorInterface[] $listExtractors + * @param iterable|PropertyTypeExtractorInterface[] $typeExtractors + * @param iterable|PropertyDescriptionExtractorInterface[] $descriptionExtractors + * @param iterable|PropertyAccessExtractorInterface[] $accessExtractors */ - public function __construct(array $listExtractors = array(), array $typeExtractors = array(), array $descriptionExtractors = array(), array $accessExtractors = array()) + public function __construct($listExtractors = array(), $typeExtractors = array(), $descriptionExtractors = array(), $accessExtractors = array()) { $this->listExtractors = $listExtractors; $this->typeExtractors = $typeExtractors; @@ -103,13 +88,13 @@ public function isWritable($class, $property, array $context = array()) /** * Iterates over registered extractors and return the first value found. * - * @param array $extractors - * @param string $method - * @param array $arguments + * @param iterable $extractors + * @param string $method + * @param array $arguments * * @return mixed */ - private function extract(array $extractors, $method, array $arguments) + private function extract($extractors, $method, array $arguments) { foreach ($extractors as $extractor) { $value = call_user_func_array(array($extractor, $method), $arguments);