Skip to content

[PropertyInfo] Use iterators for PropertyInfoExtractor #21654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
33 changes: 9 additions & 24 deletions src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterable is not a valid keyword, even according to the (still) draft PSR-5. See phpDocumentor/fig-standards#141

But anyway I think it's redundant to write it like this, it should be simply iterable<PropertyListExtractorInterface>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor is @final, its support will come when it will be adopted so imo it's not a problem.

About the redundancy I agree but we would lose all completion until editors add generics support, I don't think it's acceptable.

Copy link
Member

@dunglas dunglas Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, the RFC for introducing an iterable keyword has been accepted and PHP 7.1 supports this type: https://wiki.php.net/rfc/iterable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dunglas That's for PHP, not PHPDoc 😄

* @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;
Expand Down Expand Up @@ -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);
Expand Down