ConstructorExtractor.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\PropertyInfo\Extractor;
  11. use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
  12. /**
  13. * Extracts the constructor argument type using ConstructorArgumentTypeExtractorInterface implementations.
  14. *
  15. * @author Dmitrii Poddubnyi <dpoddubny@gmail.com>
  16. */
  17. final class ConstructorExtractor implements PropertyTypeExtractorInterface
  18. {
  19. /** @var iterable|ConstructorArgumentTypeExtractorInterface[] */
  20. private $extractors;
  21. /**
  22. * @param iterable|ConstructorArgumentTypeExtractorInterface[] $extractors
  23. */
  24. public function __construct(iterable $extractors = [])
  25. {
  26. $this->extractors = $extractors;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getTypes($class, $property, array $context = [])
  32. {
  33. foreach ($this->extractors as $extractor) {
  34. $value = $extractor->getTypesFromConstructor($class, $property);
  35. if (null !== $value) {
  36. return $value;
  37. }
  38. }
  39. return null;
  40. }
  41. }