ContainerInterface.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * @param string $id The service identifier
  32. * @param object|null $service The service instance
  33. */
  34. public function set($id, $service);
  35. /**
  36. * Gets a service.
  37. *
  38. * @param string $id The service identifier
  39. * @param int $invalidBehavior The behavior when the service does not exist
  40. *
  41. * @return object|null The associated service
  42. *
  43. * @throws ServiceCircularReferenceException When a circular reference is detected
  44. * @throws ServiceNotFoundException When the service is not defined
  45. *
  46. * @see Reference
  47. */
  48. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  49. /**
  50. * Returns true if the given service is defined.
  51. *
  52. * @param string $id The service identifier
  53. *
  54. * @return bool true if the service is defined, false otherwise
  55. */
  56. public function has($id);
  57. /**
  58. * Check for whether or not a service has been initialized.
  59. *
  60. * @param string $id
  61. *
  62. * @return bool true if the service has been initialized, false otherwise
  63. */
  64. public function initialized($id);
  65. /**
  66. * Gets a parameter.
  67. *
  68. * @param string $name The parameter name
  69. *
  70. * @return array|bool|float|int|string|null The parameter value
  71. *
  72. * @throws InvalidArgumentException if the parameter is not defined
  73. */
  74. public function getParameter($name);
  75. /**
  76. * Checks if a parameter exists.
  77. *
  78. * @param string $name The parameter name
  79. *
  80. * @return bool The presence of parameter in container
  81. */
  82. public function hasParameter($name);
  83. /**
  84. * Sets a parameter.
  85. *
  86. * @param string $name The parameter name
  87. * @param mixed $value The parameter value
  88. */
  89. public function setParameter($name, $value);
  90. }