Reference.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * Note: The $strict parameter is deprecated since version 2.8 and will be removed in 3.0.
  23. *
  24. * @param string $id The service identifier
  25. * @param int $invalidBehavior The behavior when the service does not exist
  26. * @param bool $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 = strtolower($id);
  33. $this->invalidBehavior = $invalidBehavior;
  34. $this->strict = $strict;
  35. }
  36. /**
  37. * @return string The service identifier
  38. */
  39. public function __toString()
  40. {
  41. return $this->id;
  42. }
  43. /**
  44. * Returns the behavior to be used when the service does not exist.
  45. *
  46. * @return int
  47. */
  48. public function getInvalidBehavior()
  49. {
  50. return $this->invalidBehavior;
  51. }
  52. /**
  53. * Returns true when this Reference is strict.
  54. *
  55. * @return bool
  56. *
  57. * @deprecated since version 2.8, to be removed in 3.0.
  58. */
  59. public function isStrict($triggerDeprecationError = true)
  60. {
  61. if ($triggerDeprecationError) {
  62. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  63. }
  64. return $this->strict;
  65. }
  66. }