ServiceClosureArgument.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 service wrapped in a memoizing closure.
  15. *
  16. * @author Nicolas Grekas <p@tchwork.com>
  17. */
  18. class ServiceClosureArgument implements ArgumentInterface
  19. {
  20. private $values;
  21. public function __construct(Reference $reference)
  22. {
  23. $this->values = [$reference];
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function getValues()
  29. {
  30. return $this->values;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function setValues(array $values)
  36. {
  37. if ([0] !== array_keys($values) || !($values[0] instanceof Reference || null === $values[0])) {
  38. throw new InvalidArgumentException('A ServiceClosureArgument must hold one and only one Reference.');
  39. }
  40. $this->values = $values;
  41. }
  42. }