Reference.php 1.9 KB

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