Copied!

ContainerBuilder is a DI container that provides an API to easily describe services.

Instantiable
Constants
public Symfony\Component\DependencyInjection\ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE = 1
public Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_INVALID_REFERENCE = 3
public Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE = 4
public Symfony\Component\DependencyInjection\ContainerInterface::NULL_ON_INVALID_REFERENCE = 2
public Symfony\Component\DependencyInjection\ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE = 0
Methods
public __construct(?Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag = NULL)
public addAliases(array $aliases)
 

Adds the service aliases.

public addCompilerPass(Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $pass, string $type = 'beforeOptimization'Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0) : static
 

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\Component\DependencyInjection\Definition
 

Registers an autowired service definition.

This method implements a shortcut for using setDefinition() with
an autowired definition.

public static Symfony\Component\DependencyInjection\Container::camelize(string $id) : string
 

Camelizes a string.

public compile(bool $resolveEnvPlaceholders = false)
 

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:

  • The extension configurations are merged;
  • Parameter values are resolved;
  • The parameter bag is frozen;
  • Extension loading is disabled.
  • param phpDocumentor\Reflection\Types\Boolean $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current
    env vars or be replaced by uniquely identifiable placeholders.
    Set to "true" when you want to use the current ContainerBuilder
    directly, keep to "false" when the container is dumped instead.
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\Component\DependencyInjection\Definition
 

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\Component\DependencyInjection\Alias
 
public getAliases() : array
public getAutoconfiguredAttributes() : array
public getAutoconfiguredInstanceof() : array
 

Returns an array of ChildDefinition[] keyed by interface.

public getCompiler() : Symfony\Component\DependencyInjection\Compiler\Compiler
 

Returns the compiler.

public getCompilerPassConfig() : Symfony\Component\DependencyInjection\Compiler\PassConfig
 

Returns the compiler pass config which can then be modified.

public getDefinition(string $id) : Symfony\Component\DependencyInjection\Definition
 

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\Component\DependencyInjection\Extension\ExtensionInterface
 

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 Symfony\Component\DependencyInjection\Container::getParameter(string $name)
 

Gets a parameter.

public Symfony\Component\DependencyInjection\Container::getParameterBag() : Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface
 

Gets the service container parameter bag.

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 Symfony\Component\DependencyInjection\Container::hasParameter(string $name) : bool
public Symfony\Component\DependencyInjection\Container::initialized(string $id) : bool
 

Returns true if the given service has actually been initialized.

public Symfony\Component\DependencyInjection\Container::isCompiled() : bool
 

Returns true if the container is compiled.

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\Component\DependencyInjection\Compiler\CompilerPassInterface $pass, string $message)
 
  • final
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
the parameters passed to the container constructor to have precedence
over the loaded ones.

$container = new ContainerBuilder(new ParameterBag(['foo' => 'bar']));
$loader = new LoaderXXX($container);
$loader->load('resource_name');
$container->register('foo', 'stdClass');

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 prependExtensionConfig(string $name, array $config)
 

Prepends a config array to the configs of the given extension.

public register(string $id, ?string $class = NULL) : Symfony\Component\DependencyInjection\Definition
 

Registers a service definition.

This methods allows for simple registration of service definition
with a fluid interface.

public registerAliasForArgument(string $id, string $type, ?string $name = NULL) : Symfony\Component\DependencyInjection\Alias
 

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 registerExtension(Symfony\Component\DependencyInjection\Extension\ExtensionInterface $extension)
public registerForAutoconfiguration(string $interface) : Symfony\Component\DependencyInjection\ChildDefinition
 

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.

  • internal
public removeDefinition(string $id)
 

Removes a service definition.

public Symfony\Component\DependencyInjection\Container::reset()
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\Component\DependencyInjection\Alias|string $id) : Symfony\Component\DependencyInjection\Alias
 

Sets an alias for an existing service.

public setAliases(array $aliases)
 

Sets the service aliases.

public setDefinition(string $id, Symfony\Component\DependencyInjection\Definition $definition) : Symfony\Component\DependencyInjection\Definition
 

Sets a service definition.

public setDefinitions(array $definitions)
 

Sets the service definitions.

public Symfony\Component\DependencyInjection\Container::setParameter(string $name, UnitEnum|array|string|int|float|bool|?null $value)
public setProxyInstantiator(Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface $proxyInstantiator)
 

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
to depend on the Config component, set this flag to false.

public static Symfony\Component\DependencyInjection\Container::underscore(string $id) : string
 

A string to underscore.

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
protected Symfony\Component\DependencyInjection\Container::$aliases
protected Symfony\Component\DependencyInjection\Container::$factories
protected Symfony\Component\DependencyInjection\Container::$fileMap
protected Symfony\Component\DependencyInjection\Container::$loading
protected Symfony\Component\DependencyInjection\Container::$methodMap
protected Symfony\Component\DependencyInjection\Container::$parameterBag
protected Symfony\Component\DependencyInjection\Container::$privates
protected Symfony\Component\DependencyInjection\Container::$resolving
protected Symfony\Component\DependencyInjection\Container::$services
protected Symfony\Component\DependencyInjection\Container::$syntheticIds
Methods
protected getEnv(string $name) : ?mixed
protected final Symfony\Component\DependencyInjection\Container::getService(string|false $registry, string $id, ?string $method, string|bool $load) : ?mixed
 
  • internal
protected Symfony\Component\DependencyInjection\Container::load(string $file)
 

Creates a service by requiring its factory file.

Constants
private Symfony\Component\DependencyInjection\ContainerBuilder::INTERNAL_TYPES = ['int' => true, 'float' => true, 'string' => true, 'bool' => true, 'resource' => true, 'object' => true, 'array' => true, 'null' => true, 'callable' => true, 'iterable' => true, 'mixed' => true]
Properties
private array $aliasDefinitions
private array $autoconfiguredAttributes
private array $autoconfiguredInstanceof
private array $classReflectors
private Symfony\Component\DependencyInjection\Compiler\Compiler $compiler
private array $definitions
private array $envCounters
 
private array $envPlaceholders
 
private Symfony\Component\DependencyInjection\ExpressionLanguage $expressionLanguage
private array $expressionLanguageProviders
private array $extensionConfigs
private array $extensions
private array $extensionsByNs
private Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface $proxyInstantiator
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\Component\DependencyInjection\Definition $definition, array $inlineServices, bool $isConstructorArgument = false, ?string $id = NULL, object|bool $tryProxy = true) : ?mixed
 

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\Component\DependencyInjection\ExpressionLanguage
private inVendors(string $path) : bool
private shareService(Symfony\Component\DependencyInjection\Definition $definition, ?mixed $service, ?string $id, array $inlineServices)
Methods
public static Symfony\Component\DependencyInjection\Container::camelize(string $id) : string
 

Camelizes a string.

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 static Symfony\Component\DependencyInjection\Container::underscore(string $id) : string
 

A string to underscore.

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.

© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration