ReferenceSetArgumentTrait.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * @author Titouan Galopin <galopintitouan@gmail.com>
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. trait ReferenceSetArgumentTrait
  18. {
  19. private $values;
  20. /**
  21. * @param Reference[] $values
  22. */
  23. public function __construct(array $values)
  24. {
  25. $this->setValues($values);
  26. }
  27. /**
  28. * @return Reference[] The values in the set
  29. */
  30. public function getValues()
  31. {
  32. return $this->values;
  33. }
  34. /**
  35. * @param Reference[] $values The service references to put in the set
  36. */
  37. public function setValues(array $values)
  38. {
  39. foreach ($values as $k => $v) {
  40. if (null !== $v && !$v instanceof Reference) {
  41. throw new InvalidArgumentException(sprintf('A "%s" must hold only Reference instances, "%s" given.', __CLASS__, get_debug_type($v)));
  42. }
  43. }
  44. $this->values = $values;
  45. }
  46. }