ConstructorExtractor.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. private $extractors;
  20. /**
  21. * @param iterable<int, ConstructorArgumentTypeExtractorInterface> $extractors
  22. */
  23. public function __construct(iterable $extractors = [])
  24. {
  25. $this->extractors = $extractors;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function getTypes(string $class, string $property, array $context = []): ?array
  31. {
  32. foreach ($this->extractors as $extractor) {
  33. $value = $extractor->getTypesFromConstructor($class, $property);
  34. if (null !== $value) {
  35. return $value;
  36. }
  37. }
  38. return null;
  39. }
  40. }