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) : void Adds the service aliases.
|
public addCompilerPass(Symfony Adds a compiler pass.
|
public addDefinitions(array $definitions) : void Adds the service definitions.
|
public addExpressionLanguageProvider(Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface $provider) : void |
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 an autowired definition. |
public compile(bool $resolveEnvPlaceholders = false) : void Compiles the container. This method passes the container to compiler passes whose job is to manipulate and optimize the container. The main compiler passes roughly do four things:
|
public deprecateParameter(string $name, string $package, string $version, string $message = 'The parameter "%s" is deprecated.') : void Deprecates a service container parameter.
|
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'); foreach ($serviceIds as $serviceId => $tags) { foreach ($tags as $tag) { echo $tag['hello']; } }
|
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) : void 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 the parameters passed to the container constructor to have precedence over the loaded ones.
In the above example, even if the loaded resource defines a foo parameter, the value will still be 'bar' as defined in the ContainerBuilder constructor.
|
public parameterCannotBeEmpty(string $name, string $message) : void |
public prependExtensionConfig(string $name, array $config) : void Prepends a config array to the configs of the given extension.
|
public register(string $id, ?string $class = NULL) : Symfony Registers a service definition. This method allows for simple registration of service definition with a fluid interface. |
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) using camel case: "foo.bar" or "foo_bar" creates an alias bound to "$fooBar"-named arguments with $type as type-hint. Such arguments will receive the service $id when autowiring is used. |
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 class/method/property/parameter that the attribute targets. Using one or many of \ReflectionClass|\ReflectionMethod|\ReflectionProperty|\ReflectionParameter as a type-hint for this argument allows filtering which attributes should be passed to the callable.
|
public registerChild(string $id, string $parent) : Symfony This method provides a fluid interface for easily registering a child service definition of the given parent service. |
public registerExtension(Symfony |
public registerForAutoconfiguration(string $interface) : Symfony Returns a ChildDefinition that will be used for autoconfiguring the interface/class. |
public removeAlias(string $alias) : void |
public removeBindings(string $id) : void Removes bindings for a service.
|
public removeDefinition(string $id) : void 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) : void Sets a service.
|
public setAlias(string $alias, Symfony Sets an alias for an existing service.
|
public setAliases(array $aliases) : void Sets the service aliases.
|
public setDefinition(string $id, Symfony Sets a service definition.
|
public setDefinitions(array $definitions) : void 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) : void Sets the track resources flag. If you are not using the loaders and therefore don't want to depend on the Config component, set this flag to false. |
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, the class will be considered available even if it is also 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 array $pathsInVendor = []
|
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, the class will be considered available even if it is also in dev-only mode.
|