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