|
| __construct (array|MutableDefinitionSource $definitions=[], ProxyFactory $proxyFactory=null, ContainerInterface $wrapperContainer=null) |
| Use $container = new Container() if you want a container with the default configuration.
|
|
| call ($callable, array $parameters=[]) |
| Call the given function using the given parameters.
|
|
| debugEntry (string $name) |
| Get entry debug information.
|
|
| get (string $id) |
| Returns an entry of the container by its name.
|
|
| getKnownEntryNames () |
| Get defined container entries.
|
|
| has (string $id) |
| Returns true if the container can return an entry for the given identifier.
|
|
| injectOn (object $instance) |
| Inject all dependencies on an existing instance.
|
|
| make (string $name, array $parameters=[]) |
| Build an entry of the container by its name.
|
|
| set (string $name, mixed $value) |
| Define an object or a value in the container.
|
|
|
static | create (array $definitions) |
|
|
| setDefinition (string $name, Definition $definition) |
|
◆ __construct()
Use $container = new Container()
if you want a container with the default configuration.
If you want to customize the container's behavior, you are discouraged to create and pass the dependencies yourself, the ContainerBuilder class is here to help you instead.
- See also
- ContainerBuilder
- Parameters
-
ContainerInterface | $wrapperContainer | If the container is wrapped by another container. |
◆ call()
DI\Container::call |
( |
| $callable, |
|
|
array | $parameters = [] ) |
Call the given function using the given parameters.
Missing parameters will be resolved from the container.
- Parameters
-
callable | array | string | $callable | Function to call. |
array | $parameters | Parameters to use. Can be indexed by the parameter names or not indexed (same order as the parameters). The array can also contain DI definitions, e.g. DI\get(). |
- Return values
-
mixed | Result of the function. |
Implements Invoker\InvokerInterface.
◆ debugEntry()
DI\Container::debugEntry |
( |
string | $name | ) |
|
Get entry debug information.
- Parameters
-
- Exceptions
-
InvalidDefinition | |
NotFoundException | |
◆ get()
DI\Container::get |
( |
string | $id | ) |
|
Returns an entry of the container by its name.
@template T
- Parameters
-
string|class-string<T> | $id Entry name or a class name. |
- Return values
-
- Exceptions
-
DependencyException | Error while resolving the entry. |
NotFoundException | No entry found for the given name. |
Implements Psr\Container\ContainerInterface.
Reimplemented in DI\CompiledContainer.
◆ getKnownEntryNames()
DI\Container::getKnownEntryNames |
( |
| ) |
|
Get defined container entries.
- Return values
-
◆ has()
DI\Container::has |
( |
string | $id | ) |
|
Returns true if the container can return an entry for the given identifier.
Returns false otherwise.
has($id)
returning true does not mean that get($id)
will not throw an exception. It does however mean that get($id)
will not throw a NotFoundExceptionInterface
.
- Parameters
-
string | $id | Identifier of the entry to look for. |
- Return values
-
Implements Psr\Container\ContainerInterface.
Reimplemented in DI\CompiledContainer.
◆ injectOn()
DI\Container::injectOn |
( |
object | $instance | ) |
|
Inject all dependencies on an existing instance.
@template T
- Parameters
-
object | T | $instance | Object to perform injection upon |
- Return values
-
object|T\$instance | Returns the same instance |
- Exceptions
-
InvalidArgumentException | |
DependencyException | Error while injecting dependencies |
◆ make()
DI\Container::make |
( |
string | $name, |
|
|
array | $parameters = [] ) |
Build an entry of the container by its name.
This method behave like get() except resolves the entry again every time. For example if the entry is a class then a new instance will be created each time.
This method makes the container behave like a factory.
@template T
- Parameters
-
| string|class-string<T> | $name Entry name or a class name. |
array | $parameters | Optional parameters to use to build the entry. Use this to force specific parameters to specific values. Parameters not defined in this array will be resolved using the container. |
- Return values
-
- Exceptions
-
InvalidArgumentException | The name parameter must be of type string. |
DependencyException | Error while resolving the entry. |
NotFoundException | No entry found for the given name. |
Implements DI\FactoryInterface.
◆ set()
DI\Container::set |
( |
string | $name, |
|
|
mixed | $value ) |
Define an object or a value in the container.
- Parameters
-
string | $name | Entry name |
mixed | DefinitionHelper | $value | Value, use definition helpers to define objects |
◆ $delegateContainer
Container that wraps this container.
If none, points to $this.
◆ $entriesBeingResolved
array DI\Container::$entriesBeingResolved = [] |
|
protected |
Array of entries being resolved.
Used to avoid circular dependencies and infinite loops.
The documentation for this class was generated from the following file:
- lib/php-di/php-di/src/Container.php