Container is a dependency injection container.
It gives access to object instances (services). Services and parameters are simple key/pair stores. The container can have four possible behaviors when a service does not exist (or is not initialized for the last case):
- EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at compilation time (the default)
- NULL_ON_INVALID_REFERENCE: Returns null
- IGNORE_ON_INVALID_REFERENCE: Ignores the wrapping command asking for the reference (for instance, ignore a setter if the service does not exist)
- IGNORE_ON_UNINITIALIZED_REFERENCE: Ignores/returns null for uninitialized services or invalid references
- RUNTIME_EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at runtime
- author Fabien Potencier
- author Johannes M.
Schmitt
- Children
- Implements
Psr\Container\ContainerInterface Symfony \Component \DependencyInjection \ContainerInterface Symfony \Contracts \Service \ResetInterface
| Constants |
| Methods |
| public __construct(?Symfony |
| public static camelize(string $id) : string Camelizes a string. |
| public compile() : void Compiles the container. This method does two things:
|
| public get(string $id, int $invalidBehavior = 1self::EXCEPTION_ON_INVALID_REFERENCE) : ?object Gets a service.
|
| public getParameter(string $name) : UnitEnum|array|string|int|float|bool|?null Gets a parameter.
|
| public getParameterBag() : Symfony Gets the service container parameter bag. |
| public getRemovedIds() : array Gets service ids that existed at compile time. |
| public getServiceIds() : array Gets all service ids.
|
| public has(string $id) : bool |
| public hasParameter(string $name) : bool |
| public initialized(string $id) : bool Returns true if the given service has actually been initialized. |
| public isCompiled() : bool Returns true if the container is compiled. |
| public reset() : void |
public resetEnvCache() : void
|
| public set(string $id, ?object $service) : void Sets a service. Setting a synthetic service to null resets it: has() returns false and get() behaves in the same way as if the service was never created. |
| public setParameter(string $name, UnitEnum|array|string|int|float|bool|?null $value) : void |
| public static underscore(string $id) : string A string to underscore. |
| Properties |
| protected array $aliases = [] |
| protected array $factories = [] |
| protected array $fileMap = [] |
| protected array $loading = [] |
| protected array $methodMap = [] |
| protected Symfony |
| protected array $privates = [] |
| protected array $resolving = [] |
| protected array $services = [] |
| protected array $syntheticIds = [] |
| Methods |
| protected getEnv(string $name) : ?mixed Fetches a variable from the environment.
|
protected final getService(string|false $registry, string $id, ?string $method, string|bool $load) : ?mixed
|
| protected load(string $file) : ?mixed Creates a service by requiring its factory file. |
| Properties |
| private bool $compiled = false |
| private array $envCache = [] |
| private Closure $getEnv |
| private static Closure $make |
| Methods |
| private __clone() |
| private static make(self $container, string $id, int $invalidBehavior) : ?object Creates a service. As a separate method to allow "get()" to use the really fast |
| Properties |
| private static Closure $make |
| Methods |
| public static camelize(string $id) : string Camelizes a string. |
| private static make(self $container, string $id, int $invalidBehavior) : ?object Creates a service. As a separate method to allow "get()" to use the really fast |
| public static underscore(string $id) : string A string to underscore. |