ReferenceConfigurator.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Loader\Configurator;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. /**
  13. * @author Nicolas Grekas <p@tchwork.com>
  14. */
  15. class ReferenceConfigurator extends AbstractConfigurator
  16. {
  17. /** @internal */
  18. protected $id;
  19. /** @internal */
  20. protected $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
  21. public function __construct(string $id)
  22. {
  23. $this->id = $id;
  24. }
  25. /**
  26. * @return $this
  27. */
  28. final public function ignoreOnInvalid(): self
  29. {
  30. $this->invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
  31. return $this;
  32. }
  33. /**
  34. * @return $this
  35. */
  36. final public function nullOnInvalid(): self
  37. {
  38. $this->invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
  39. return $this;
  40. }
  41. /**
  42. * @return $this
  43. */
  44. final public function ignoreOnUninitialized(): self
  45. {
  46. $this->invalidBehavior = ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE;
  47. return $this;
  48. }
  49. /**
  50. * @return string
  51. */
  52. public function __toString()
  53. {
  54. return $this->id;
  55. }
  56. }