ContainerInterface.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  12. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  13. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  14. /**
  15. * ContainerInterface is the interface implemented by service container classes.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  19. *
  20. * @api
  21. */
  22. interface ContainerInterface
  23. {
  24. const EXCEPTION_ON_INVALID_REFERENCE = 1;
  25. const NULL_ON_INVALID_REFERENCE = 2;
  26. const IGNORE_ON_INVALID_REFERENCE = 3;
  27. const SCOPE_CONTAINER = 'container';
  28. const SCOPE_PROTOTYPE = 'prototype';
  29. /**
  30. * Sets a service.
  31. *
  32. * @param string $id The service identifier
  33. * @param object $service The service instance
  34. * @param string $scope The scope of the service
  35. *
  36. * @api
  37. */
  38. public function set($id, $service, $scope = self::SCOPE_CONTAINER);
  39. /**
  40. * Gets a service.
  41. *
  42. * @param string $id The service identifier
  43. * @param int $invalidBehavior The behavior when the service does not exist
  44. *
  45. * @return object The associated service
  46. *
  47. * @throws InvalidArgumentException if the service is not defined
  48. * @throws ServiceCircularReferenceException When a circular reference is detected
  49. * @throws ServiceNotFoundException When the service is not defined
  50. *
  51. * @see Reference
  52. *
  53. * @api
  54. */
  55. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  56. /**
  57. * Returns true if the given service is defined.
  58. *
  59. * @param string $id The service identifier
  60. *
  61. * @return Boolean true if the service is defined, false otherwise
  62. *
  63. * @api
  64. */
  65. public function has($id);
  66. /**
  67. * Gets a parameter.
  68. *
  69. * @param string $name The parameter name
  70. *
  71. * @return mixed The parameter value
  72. *
  73. * @throws InvalidArgumentException if the parameter is not defined
  74. *
  75. * @api
  76. */
  77. public function getParameter($name);
  78. /**
  79. * Checks if a parameter exists.
  80. *
  81. * @param string $name The parameter name
  82. *
  83. * @return Boolean The presence of parameter in container
  84. *
  85. * @api
  86. */
  87. public function hasParameter($name);
  88. /**
  89. * Sets a parameter.
  90. *
  91. * @param string $name The parameter name
  92. * @param mixed $value The parameter value
  93. *
  94. * @api
  95. */
  96. public function setParameter($name, $value);
  97. /**
  98. * Enters the given scope
  99. *
  100. * @param string $name
  101. *
  102. * @api
  103. */
  104. public function enterScope($name);
  105. /**
  106. * Leaves the current scope, and re-enters the parent scope
  107. *
  108. * @param string $name
  109. *
  110. * @api
  111. */
  112. public function leaveScope($name);
  113. /**
  114. * Adds a scope to the container
  115. *
  116. * @param ScopeInterface $scope
  117. *
  118. * @api
  119. */
  120. public function addScope(ScopeInterface $scope);
  121. /**
  122. * Whether this container has the given scope
  123. *
  124. * @param string $name
  125. *
  126. * @return Boolean
  127. *
  128. * @api
  129. */
  130. public function hasScope($name);
  131. /**
  132. * Determines whether the given scope is currently active.
  133. *
  134. * It does however not check if the scope actually exists.
  135. *
  136. * @param string $name
  137. *
  138. * @return Boolean
  139. *
  140. * @api
  141. */
  142. public function isScopeActive($name);
  143. }