ContainerInterface.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. use Psr\Container\ContainerInterface as PsrContainerInterface;
  12. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  13. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  14. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  15. /**
  16. * ContainerInterface is the interface implemented by service container classes.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  20. */
  21. interface ContainerInterface extends PsrContainerInterface
  22. {
  23. public const RUNTIME_EXCEPTION_ON_INVALID_REFERENCE = 0;
  24. public const EXCEPTION_ON_INVALID_REFERENCE = 1;
  25. public const NULL_ON_INVALID_REFERENCE = 2;
  26. public const IGNORE_ON_INVALID_REFERENCE = 3;
  27. public const IGNORE_ON_UNINITIALIZED_REFERENCE = 4;
  28. /**
  29. * Sets a service.
  30. */
  31. public function set(string $id, ?object $service);
  32. /**
  33. * Gets a service.
  34. *
  35. * @param string $id The service identifier
  36. * @param int $invalidBehavior The behavior when the service does not exist
  37. *
  38. * @return object|null The associated service
  39. *
  40. * @throws ServiceCircularReferenceException When a circular reference is detected
  41. * @throws ServiceNotFoundException When the service is not defined
  42. *
  43. * @see Reference
  44. */
  45. public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  46. /**
  47. * Returns true if the given service is defined.
  48. *
  49. * @param string $id The service identifier
  50. *
  51. * @return bool true if the service is defined, false otherwise
  52. */
  53. public function has($id);
  54. /**
  55. * Check for whether or not a service has been initialized.
  56. *
  57. * @return bool true if the service has been initialized, false otherwise
  58. */
  59. public function initialized(string $id);
  60. /**
  61. * Gets a parameter.
  62. *
  63. * @param string $name The parameter name
  64. *
  65. * @return array|bool|float|int|string|null The parameter value
  66. *
  67. * @throws InvalidArgumentException if the parameter is not defined
  68. */
  69. public function getParameter(string $name);
  70. /**
  71. * Checks if a parameter exists.
  72. *
  73. * @param string $name The parameter name
  74. *
  75. * @return bool The presence of parameter in container
  76. */
  77. public function hasParameter(string $name);
  78. /**
  79. * Sets a parameter.
  80. *
  81. * @param string $name The parameter name
  82. * @param mixed $value The parameter value
  83. */
  84. public function setParameter(string $name, $value);
  85. }