Reference.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * @api
  17. */
  18. class Reference
  19. {
  20. private $id;
  21. private $invalidBehavior;
  22. private $strict;
  23. /**
  24. * Constructor.
  25. *
  26. * @param string $id The service identifier
  27. * @param int $invalidBehavior The behavior when the service does not exist
  28. * @param Boolean $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 (string) $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 Boolean
  60. */
  61. public function isStrict()
  62. {
  63. return $this->strict;
  64. }
  65. }