4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection
;
14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
;
15 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
;
16 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
;
19 * ContainerInterface is the interface implemented by service container classes.
21 * @author Fabien Potencier <fabien@symfony.com>
22 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
24 interface ContainerInterface
26 const EXCEPTION_ON_INVALID_REFERENCE
= 1;
27 const NULL_ON_INVALID_REFERENCE
= 2;
28 const IGNORE_ON_INVALID_REFERENCE
= 3;
29 const SCOPE_CONTAINER
= 'container';
30 const SCOPE_PROTOTYPE
= 'prototype';
35 * @param string $id The service identifier
36 * @param object $service The service instance
37 * @param string $scope The scope of the service
39 public function set($id, $service, $scope = self
::SCOPE_CONTAINER
);
44 * @param string $id The service identifier
45 * @param int $invalidBehavior The behavior when the service does not exist
47 * @return object The associated service
49 * @throws ServiceCircularReferenceException When a circular reference is detected
50 * @throws ServiceNotFoundException When the service is not defined
54 public function get($id, $invalidBehavior = self
::EXCEPTION_ON_INVALID_REFERENCE
);
57 * Returns true if the given service is defined.
59 * @param string $id The service identifier
61 * @return bool true if the service is defined, false otherwise
63 public function has($id);
68 * @param string $name The parameter name
70 * @return mixed The parameter value
72 * @throws InvalidArgumentException if the parameter is not defined
74 public function getParameter($name);
77 * Checks if a parameter exists.
79 * @param string $name The parameter name
81 * @return bool The presence of parameter in container
83 public function hasParameter($name);
88 * @param string $name The parameter name
89 * @param mixed $value The parameter value
91 public function setParameter($name, $value);
94 * Enters the given scope.
98 public function enterScope($name);
101 * Leaves the current scope, and re-enters the parent scope.
103 * @param string $name
105 public function leaveScope($name);
108 * Adds a scope to the container.
110 * @param ScopeInterface $scope
112 public function addScope(ScopeInterface
$scope);
115 * Whether this container has the given scope.
117 * @param string $name
121 public function hasScope($name);
124 * Determines whether the given scope is currently active.
126 * It does however not check if the scope actually exists.
128 * @param string $name
132 public function isScopeActive($name);