ContainerInterface.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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.potencier@symfony-project.com>
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. interface ContainerInterface
  18. {
  19. const EXCEPTION_ON_INVALID_REFERENCE = 1;
  20. const NULL_ON_INVALID_REFERENCE = 2;
  21. const IGNORE_ON_INVALID_REFERENCE = 3;
  22. const SCOPE_CONTAINER = 'container';
  23. const SCOPE_PROTOTYPE = 'prototype';
  24. /**
  25. * Sets a service.
  26. *
  27. * @param string $id The service identifier
  28. * @param object $service The service instance
  29. * @param string $scope The scope of the service
  30. */
  31. function set($id, $service, $scope = self::SCOPE_CONTAINER);
  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 The associated service
  39. *
  40. * @throws \InvalidArgumentException if the service is not defined
  41. *
  42. * @see Reference
  43. */
  44. function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  45. /**
  46. * Returns true if the given service is defined.
  47. *
  48. * @param string $id The service identifier
  49. *
  50. * @return Boolean true if the service is defined, false otherwise
  51. */
  52. function has($id);
  53. /**
  54. * Gets a parameter.
  55. *
  56. * @param string $name The parameter name
  57. *
  58. * @return mixed The parameter value
  59. *
  60. * @throws \InvalidArgumentException if the parameter is not defined
  61. */
  62. function getParameter($name);
  63. /**
  64. * Checks if a parameter exists.
  65. *
  66. * @param string $name The parameter name
  67. *
  68. * @return Boolean The presence of parameter in container
  69. */
  70. function hasParameter($name);
  71. /**
  72. * Sets a parameter.
  73. *
  74. * @param string $name The parameter name
  75. * @param mixed $parameters The parameter value
  76. */
  77. function setParameter($name, $value);
  78. /**
  79. * Enters the given scope
  80. *
  81. * @param string $name
  82. * @return void
  83. */
  84. function enterScope($name);
  85. /**
  86. * Leaves the current scope, and re-enters the parent scope
  87. *
  88. * @param string $name
  89. * @return void
  90. */
  91. function leaveScope($name);
  92. /**
  93. * Adds a scope to the container
  94. *
  95. * @param ScopeInterface $scope
  96. * @return void
  97. */
  98. function addScope(ScopeInterface $scope);
  99. /**
  100. * Whether this container has the given scope
  101. *
  102. * @param string $name
  103. * @return Boolean
  104. */
  105. function hasScope($name);
  106. /**
  107. * Determines whether the given scope is currently active.
  108. *
  109. * It does however not check if the scope actually exists.
  110. *
  111. * @return Boolean
  112. */
  113. function isScopeActive($name);
  114. }