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.

  • param array | Alias> $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.

  • param string $type The type of compiler pass
  • param int $priority Used to sort the passes
  • return $this
public addDefinitions ( array $definitions )
 

Adds the service definitions.

  • param array $definitions
public addExpressionLanguageProvider ( Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface $provider )
public addObjectResource ( object | string $object ) : static
 

Adds the object class hierarchy as resources.

  • param object | string $object An object instance or class name
  • return $this
public addResource ( Symfony\Component\Config\Resource\ResourceInterface $resource ) : static
 
  • return $this
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.
public fileExists ( string $path , string | bool $trackContents = true ) : bool
 

Checks whether the requested file or directory exists and registers the result for resource tracking.

  • param string $path The file or directory path for which to check the existence
  • param bool | string $trackContents Whether to track contents of the given resource. If a string is passed,
    it will be used as pattern for tracking contents of the requested directory
  • final
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.

  • throws ServiceNotFoundException if the service definition does not exist
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'];
}

}

  • return array An array of tags with the tagged service as key, holding a list of attribute arrays
public findTags () : array
 

Returns all tags the defined services use.

  • return string []
public findUnusedTags () : array
 

Returns all tags not queried by findTaggedServiceIds.

  • return string []
public get ( string $id , int $invalidBehavior = 1 Symfony\Component\DependencyInjection\ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) : ? object
 
  • throws ServiceCircularReferenceException When a circular reference is detected
  • throws ServiceNotFoundException When the service is not defined
  • throws Exception if an exception has been thrown when the service has been resolved
  • see \Reference
  • throws ServiceCircularReferenceException When a circular reference is detected
  • throws ServiceNotFoundException When the service is not defined
  • throws Exception
  • see \Reference
public getAlias ( string $id ) : Symfony\Component\DependencyInjection\Alias
 
  • throws InvalidArgumentException if the alias does not exist
public getAliases () : array
 
  • return array
public getAutoconfiguredAttributes () : array
 
  • return array
public getAutoconfiguredInstanceof () : array
 

Returns an array of ChildDefinition[] keyed by interface.

  • return array
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.

  • throws ServiceNotFoundException if the service definition does not exist
public getDefinitions () : array
 

Gets all service definitions.

  • return array
public getEnvCounters () : array
 

Get statistics about env usage.

  • return int [] The number of time each env vars has been resolved
public getExpressionLanguageProviders () : array
 
  • return ExpressionFunctionProviderInterface []
public getExtension ( string $name ) : Symfony\Component\DependencyInjection\Extension\ExtensionInterface
 

Returns an extension by alias or namespace.

  • throws LogicException if the extension is not registered
public getExtensionConfig ( string $name ) : array
 

Returns the configuration array for the given extension.

  • return array []
public getExtensions () : array
 

Returns all registered extensions.

  • return array
public static getInitializedConditionals ( ? mixed $value ) : array
 
  • return string []
  • internal
public Symfony\Component\DependencyInjection\Container :: getParameter ( string $name )
 

Gets a parameter.

  • return array | bool | string | int | float | UnitEnum | null
  • throws InvalidArgumentException if the parameter is not defined
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.

  • throws ReflectionException when a parent class/interface/trait is not found and $throw is true
  • final
public getRemovedBindingIds () : array
 

Gets removed binding ids.

  • return array
  • internal
public getRemovedIds () : array
 

Gets removed service or alias ids.

public getResources () : array
 

Returns an array of resources loaded to build this configuration.

  • return ResourceInterface []
public static getServiceConditionals ( ? mixed $value ) : array
 
  • return string []
  • internal
public getServiceIds () : array
 

Gets all service ids.

  • return string []
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.

  • param string $extension The extension alias or namespace
  • param array | null $values An array of values that customizes the extension
  • return $this
  • throws BadMethodCallException When this ContainerBuilder is compiled
  • throws LogicException if the extension is not registered
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.

  • throws BadMethodCallException When this ContainerBuilder is compiled
public prependExtensionConfig ( string $name , array $config )
 

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

  • param array $config
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.

  • template T
  • param class-string<\T> $attributeClass
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.

  • param string | true | null $format A sprintf() format returning the replacement for each env var name or
    null to resolve back to the original "%env(VAR)%" format or
    true to resolve to the actual values of the referenced env vars
  • param array $usedEnvs Env vars found while resolving are added to this array
  • return mixed The value with env parameters resolved if a string or an array is passed
public resolveServices ( ? mixed $value ) : ? mixed
 

Replaces service references by the real service instance and evaluates expressions.

  • return mixed The same value with all service references replaced by
    the real service instances and all expressions evaluated
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.

  • throws InvalidArgumentException if the id is not a string or an Alias
  • throws InvalidArgumentException if the alias is for itself
public setAliases ( array $aliases )
 

Sets the service aliases.

  • param array | Alias> $aliases
public setDefinition ( string $id , Symfony\Component\DependencyInjection\Definition $definition ) : Symfony\Component\DependencyInjection\Definition
 

Sets a service definition.

  • throws BadMethodCallException When this ContainerBuilder is compiled
public setDefinitions ( array $definitions )
 

Sets the service definitions.

  • param array $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.

  • param array $resources
  • return $this
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.

  • throws LogicException If dependencies have been installed with Composer 1
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
 

Fetches a variable from the environment.

  • throws EnvNotFoundException When the environment variable is not found and has no default value
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
 
  • var array
private array $autoconfiguredAttributes
 
  • var array
private array $autoconfiguredInstanceof
 
  • var array
private array $classReflectors
 
  • var array
private Symfony\Component\DependencyInjection\Compiler\Compiler $compiler
private array $definitions
 
  • var array
private array $envCounters
 
  • var int [] a map of env vars to their resolution counter
private array $envPlaceholders
 
  • var string [] a map of env var names to their placeholders
private Symfony\Component\DependencyInjection\ExpressionLanguage $expressionLanguage
private array $expressionLanguageProviders
 
  • var ExpressionFunctionProviderInterface []
private array $extensionConfigs
 
  • var array> []
private array $extensions
 
  • var array
private array $extensionsByNs
 
  • var array
private Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface $proxyInstantiator
private array $removedBindingIds
 
  • var array
private array $removedIds
 
  • var array
private array $resources
 
  • var array
private bool $trackResources
private array $usedTags
 
  • var string [] with tag names used by findTaggedServiceIds
private array $vendors
 
  • var string [] the list of vendor directories
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 , bool $tryProxy = true ) : ? mixed
 

Creates a service for a service definition.

  • throws RuntimeException When the factory definition is incomplete
  • throws RuntimeException When the service is a synthetic service
  • throws InvalidArgumentException When configure callable is not callable
private doGet ( string $id , int $invalidBehavior = 1 Symfony\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
 
  • return string []
  • internal
public static getServiceConditionals ( ? mixed $value ) : array
 
  • return string []
  • internal
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.

  • throws LogicException If dependencies have been installed with Composer 1
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration