BoundArgument.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /**
  12. * @author Guilhem Niot <guilhem.niot@gmail.com>
  13. */
  14. final class BoundArgument implements ArgumentInterface
  15. {
  16. public const SERVICE_BINDING = 0;
  17. public const DEFAULTS_BINDING = 1;
  18. public const INSTANCEOF_BINDING = 2;
  19. private static $sequence = 0;
  20. private $value;
  21. private $identifier;
  22. private $used;
  23. private $type;
  24. private $file;
  25. public function __construct($value, bool $trackUsage = true, int $type = 0, string $file = null)
  26. {
  27. $this->value = $value;
  28. if ($trackUsage) {
  29. $this->identifier = ++self::$sequence;
  30. } else {
  31. $this->used = true;
  32. }
  33. $this->type = $type;
  34. $this->file = $file;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getValues(): array
  40. {
  41. return [$this->value, $this->identifier, $this->used, $this->type, $this->file];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function setValues(array $values)
  47. {
  48. if (5 === \count($values)) {
  49. [$this->value, $this->identifier, $this->used, $this->type, $this->file] = $values;
  50. } else {
  51. [$this->value, $this->identifier, $this->used] = $values;
  52. }
  53. }
  54. }