ContainerInterface.php 2.8 KB

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