ContainerBuilder is a DI container that provides an API to easily describe services.
- author Fabien Potencier
Constants |
Methods |
public __construct(?Symfony |
public addAliases(array $aliases) Adds the service aliases.
|
public addCompilerPass(Symfony Adds a compiler pass.
|
public addDefinitions(array $definitions) Adds the service definitions.
|
public addExpressionLanguageProvider(Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface $provider) |
public addObjectResource(object|string $object) : static Adds the object class hierarchy as resources.
|
public addResource(Symfony\Component\Config\Resource\ResourceInterface $resource) : static |
public autowire(string $id, ?string $class = NULL) : Symfony Registers an autowired service definition. This method implements a shortcut for using setDefinition() with |
public compile(bool $resolveEnvPlaceholders = false) Compiles the container. This method passes the container to compiler The main compiler passes roughly do four things:
|
public fileExists(string $path, string|bool $trackContents = true) : bool Checks whether the requested file or directory exists and registers the result for resource tracking.
|
public findDefinition(string $id) : Symfony Gets a service definition by id or alias. The method "unaliases" recursively to return a Definition instance.
|
public findTaggedServiceIds(string $name, bool $throwOnAbstract = false) : array Returns service ids for a given tag. Example: $container->register('foo')->addTag('my.tag', ['hello' => 'world']); $serviceIds = $container->findTaggedServiceIds('my.tag');
}
|
public findTags() : array Returns all tags the defined services use. |
public findUnusedTags() : array Returns all tags not queried by findTaggedServiceIds. |
public get(string $id, int $invalidBehavior = 1Symfony\Component\DependencyInjection\ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) : ?object
|
public getAlias(string $id) : Symfony
|
public getAliases() : array |
public getAutoconfiguredAttributes() : array |
public getAutoconfiguredInstanceof() : array Returns an array of ChildDefinition[] keyed by interface. |
public getCompiler() : Symfony Returns the compiler. |
public getCompilerPassConfig() : Symfony Returns the compiler pass config which can then be modified. |
public getDefinition(string $id) : Symfony Gets a service definition.
|
public getDefinitions() : array Gets all service definitions. |
public getEnvCounters() : array Get statistics about env usage.
|
public getExpressionLanguageProviders() : array |
public getExtension(string $name) : Symfony Returns an extension by alias or namespace.
|
public getExtensionConfig(string $name) : array Returns the configuration array for the given extension. |
public getExtensions() : array Returns all registered extensions. |
public static getInitializedConditionals(?mixed $value) : array
|
public getReflectionClass(?string $class, bool $throw = true) : ?ReflectionClass Retrieves the requested reflection class and registers it for resource tracking.
|
public getRemovedBindingIds() : array Gets removed binding ids.
|
public getRemovedIds() : array Gets removed service or alias ids. |
public getResources() : array Returns an array of resources loaded to build this configuration. |
public static getServiceConditionals(?mixed $value) : array
|
public getServiceIds() : array |
public has(string $id) : bool |
public hasAlias(string $id) : bool |
public hasDefinition(string $id) : bool Returns true if a service definition exists under the given identifier. |
public hasExtension(string $name) : bool Checks if we have an extension. |
public static hash(?mixed $value) : string Computes a reasonably unique hash of a serializable value. |
public isTrackingResources() : bool Checks if resources are tracked. |
public loadFromExtension(string $extension, ?array $values = NULL) : static Loads the configuration for an extension.
|
public log(Symfony
|
public merge(self $container) Merges a ContainerBuilder with the current ContainerBuilder configuration. Service definitions overrides the current defined ones. But for parameters, they are overridden by the current ones. It allows
In the above example, even if the loaded resource defines a foo
|
public prependExtensionConfig(string $name, array $config) Prepends a config array to the configs of the given extension.
|
public register(string $id, ?string $class = NULL) : Symfony Registers a service definition. This methods allows for simple registration of service definition |
public registerAliasForArgument(string $id, string $type, ?string $name = NULL) : Symfony Registers an autowiring alias that only binds to a specific argument name. The argument name is derived from $name if provided (from $id otherwise) |
public registerAttributeForAutoconfiguration(string $attributeClass, callable $configurator) : void Registers an attribute that will be used for autoconfiguring annotated classes. The third argument passed to the callable is the reflector of the
|
public registerExtension(Symfony |
public registerForAutoconfiguration(string $interface) : Symfony Returns a ChildDefinition that will be used for autoconfiguring the interface/class. |
public removeAlias(string $alias) |
public removeBindings(string $id) Removes bindings for a service.
|
public removeDefinition(string $id) Removes a service definition. |
public resolveEnvPlaceholders(?mixed $value, string|bool|?null $format = NULL, ?array $usedEnvs = NULL) : ?mixed Resolves env parameter placeholders in a string or an array.
|
public resolveServices(?mixed $value) : ?mixed Replaces service references by the real service instance and evaluates expressions.
|
public set(string $id, ?object $service) Sets a service.
|
public setAlias(string $alias, Symfony Sets an alias for an existing service.
|
public setAliases(array $aliases) Sets the service aliases.
|
public setDefinition(string $id, Symfony Sets a service definition.
|
public setDefinitions(array $definitions) Sets the service definitions.
|
public setProxyInstantiator(Symfony Sets the instantiator to be used when fetching proxies. |
public setResources(array $resources) : static Sets the resources for this configuration.
|
public setResourceTracking(bool $track) Sets the track resources flag. If you are not using the loaders and therefore don't want |
public final static willBeAvailable(string $package, string $class, array $parentPackages) : bool Checks whether a class is available and will remain available in the "no-dev" mode of Composer. When parent packages are provided and if any of them is in dev-only mode,
|
Properties |
Methods |
protected getEnv(string $name) : ?mixed |
Constants |
private Symfony |
Properties |
private array $aliasDefinitions |
private array $autoconfiguredAttributes |
private array $autoconfiguredInstanceof |
private array $classReflectors |
private Symfony |
private array $definitions |
private array $envCounters
|
private array $envPlaceholders
|
private Symfony |
private array $expressionLanguageProviders |
private array $extensionConfigs |
private array $extensions |
private array $extensionsByNs |
private Symfony |
private array $removedBindingIds |
private array $removedIds |
private array $resources |
private bool $trackResources |
private array $usedTags
|
private array $vendors
|
Methods |
private callMethod(object $service, array $call, array $inlineServices) : ?mixed |
private createService(Symfony Creates a service for a service definition.
|
private doGet(string $id, int $invalidBehavior = 1Symfony\Component\DependencyInjection\ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, ?array $inlineServices = NULL, bool $isConstructorArgument = false) : ?mixed |
private doResolveServices(?mixed $value, array $inlineServices = [], bool $isConstructorArgument = false) : ?mixed |
private getExpressionLanguage() : Symfony |
private inVendors(string $path) : bool |
private shareService(Symfony |
Methods |
public static getInitializedConditionals(?mixed $value) : array
|
public static getServiceConditionals(?mixed $value) : array
|
public static hash(?mixed $value) : string Computes a reasonably unique hash of a serializable value. |
public final static willBeAvailable(string $package, string $class, array $parentPackages) : bool Checks whether a class is available and will remain available in the "no-dev" mode of Composer. When parent packages are provided and if any of them is in dev-only mode,
|