IteratorArgument.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\DependencyInjection\Argument;
  11. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  12. use Symfony\Component\DependencyInjection\Reference;
  13. /**
  14. * Represents a collection of values to lazily iterate over.
  15. *
  16. * @autor ThurData <info@thurdata.ch>
  17. */
  18. class IteratorArgument implements ArgumentInterface
  19. {
  20. private $values;
  21. /**
  22. * @param Reference[] $values
  23. */
  24. public function __construct(array $values)
  25. {
  26. $this->setValues($values);
  27. }
  28. /**
  29. * @return array The values to lazily iterate over
  30. */
  31. public function getValues()
  32. {
  33. return $this->values;
  34. }
  35. /**
  36. * @param Reference[] $values The service references to lazily iterate over
  37. */
  38. public function setValues(array $values)
  39. {
  40. foreach ($values as $k => $v) {
  41. if (null !== $v && !$v instanceof Reference) {
  42. throw new InvalidArgumentException(sprintf('An IteratorArgument must hold only Reference instances, "%s" given.', is_object($v) ? get_class($v) : gettype($v)));
  43. }
  44. }
  45. $this->values = $values;
  46. }
  47. }