Reference.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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;
  11. /**
  12. * Reference represents a service reference.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class Reference
  17. {
  18. private $id;
  19. private $invalidBehavior;
  20. /**
  21. * @param string $id The service identifier
  22. * @param int $invalidBehavior The behavior when the service does not exist
  23. *
  24. * @see Container
  25. */
  26. public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
  27. {
  28. $this->id = (string) $id;
  29. $this->invalidBehavior = $invalidBehavior;
  30. }
  31. /**
  32. * @return string The service identifier
  33. */
  34. public function __toString()
  35. {
  36. return $this->id;
  37. }
  38. /**
  39. * Returns the behavior to be used when the service does not exist.
  40. *
  41. * @return int
  42. */
  43. public function getInvalidBehavior()
  44. {
  45. return $this->invalidBehavior;
  46. }
  47. }