Reference.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. private $strict;
  21. /**
  22. * Constructor.
  23. *
  24. * @param string $id The service identifier
  25. * @param int $invalidBehavior The behavior when the service does not exist
  26. * @param Boolean $strict Sets how this reference is validated
  27. *
  28. * @see Container
  29. */
  30. public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict = true)
  31. {
  32. $this->id = $id;
  33. $this->invalidBehavior = $invalidBehavior;
  34. $this->strict = $strict;
  35. }
  36. /**
  37. * __toString.
  38. *
  39. * @return string The service identifier
  40. */
  41. public function __toString()
  42. {
  43. return (string) $this->id;
  44. }
  45. /**
  46. * Returns the behavior to be used when the service does not exist.
  47. *
  48. * @return int
  49. */
  50. public function getInvalidBehavior()
  51. {
  52. return $this->invalidBehavior;
  53. }
  54. /**
  55. * Returns true when this Reference is strict
  56. *
  57. * @return boolean
  58. */
  59. public function isStrict()
  60. {
  61. return $this->strict;
  62. }
  63. }