class MergeExtensionConfigurationContainerBuilder extends ContainerBuilder

A container builder preventing using methods that wouldn't have any effect from extensions.

Properties

protected $parameterBag from Container
protected $services from Container
protected $privates from Container
protected $fileMap from Container
protected $methodMap from Container
protected $factories from Container
protected $aliases from Container
protected $loading from Container
protected $resolving from Container
protected $syntheticIds from Container

Methods

__construct(ExtensionInterface $extension, ParameterBagInterface $parameterBag = null)

No description

compile(bool $resolveEnvPlaceholders = false)

Compiles the container.

bool
isCompiled()

Returns true if the container is compiled.

from Container
getParameterBag()

Gets the service container parameter bag.

from Container
mixed
getParameter(string $name)

Gets a parameter.

from Container
bool
hasParameter(string $name)

Checks if a parameter exists.

from Container
setParameter(string $name, mixed $value)

Sets a parameter.

from Container
set(string $id, object $service)

Sets a service.

bool
has(string $id)

Returns true if the given service is defined.

object
get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)

Gets a service.

bool
initialized(string $id)

Returns true if the given service has actually been initialized.

from Container
reset()

Resets shared services from the container.

from Container
array
getServiceIds()

Gets all service ids.

array
getRemovedIds()

Gets removed service or alias ids.

static string
camelize(string $id)

Camelizes a string.

from Container
static string
underscore(string $id)

A string to underscore.

from Container
object
load($file)

Creates a service by requiring its factory file.

from Container
mixed
getEnv(string $name)

Fetches a variable from the environment.

getService($registry, $id, $method, $load)

No description

from Container
setResourceTracking(bool $track)

Sets the track resources flag.

bool
isTrackingResources()

Checks if resources are tracked.

setProxyInstantiator(InstantiatorInterface $proxyInstantiator)

Sets the instantiator to be used when fetching proxies.

registerExtension(ExtensionInterface $extension)

No description

getExtension(string $name)

Returns an extension by alias or namespace.

getExtensions()

Returns all registered extensions.

bool
hasExtension(string $name)

Checks if we have an extension.

getResources()

Returns an array of resources loaded to build this configuration.

$this
addResource(ResourceInterface $resource)

No description

$this
setResources(array $resources)

Sets the resources for this configuration.

$this
addObjectResource(object|string $object)

Adds the object class hierarchy as resources.

ReflectionClass|null
getReflectionClass(string|null $class, bool $throw = true)

Retrieves the requested reflection class and registers it for resource tracking.

bool
fileExists(string $path, bool|string $trackContents = true)

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

$this
loadFromExtension(string $extension, array $values = null)

Loads the configuration for an extension.

$this
addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)

Adds a compiler pass.

getCompilerPassConfig()

Returns the compiler pass config which can then be modified.

getCompiler()

Returns the compiler.

removeDefinition(string $id)

Removes a service definition.

merge(ContainerBuilder $container)

Merges a ContainerBuilder with the current ContainerBuilder configuration.

array
getExtensionConfig(string $name)

Returns the configuration array for the given extension.

prependExtensionConfig(string $name, array $config)

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

addAliases(array $aliases)

Adds the service aliases.

setAliases(array $aliases)

Sets the service aliases.

setAlias(string $alias, string|Alias $id)

Sets an alias for an existing service.

removeAlias(string $alias)

Removes an alias.

bool
hasAlias(string $id)

Returns true if an alias exists under the given identifier.

Alias[]
getAliases()

Gets all defined aliases.

getAlias(string $id)

Gets an alias.

register($id, $class = null)

Registers a service definition.

autowire(string $id, string|null $class = null)

Registers an autowired service definition.

addDefinitions(array $definitions)

Adds the service definitions.

setDefinitions(array $definitions)

Sets the service definitions.

getDefinitions()

Gets all service definitions.

setDefinition(string $id, Definition $definition)

Sets a service definition.

bool
hasDefinition(string $id)

Returns true if a service definition exists under the given identifier.

getDefinition(string $id)

Gets a service definition.

findDefinition(string $id)

Gets a service definition by id or alias.

mixed
resolveServices(mixed $value)

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

array
findTaggedServiceIds(string $name, bool $throwOnAbstract = false)

Returns service ids for a given tag.

array
findTags()

Returns all tags the defined services use.

string[]
findUnusedTags()

Returns all tags not queried by findTaggedServiceIds.

registerForAutoconfiguration(string $interface)

Returns a ChildDefinition that will be used for autoconfiguring the interface/class.

registerAliasForArgument(string $id, string $type, string $name = null)

Registers an autowiring alias that only binds to a specific argument name.

getAutoconfiguredInstanceof()

Returns an array of ChildDefinition[] keyed by interface.

mixed
resolveEnvPlaceholders(mixed $value, string|true|null $format = null, array $usedEnvs = null)

Resolves env parameter placeholders in a string or an array.

int[]
getEnvCounters()

Get statistics about env usage.

log(CompilerPassInterface $pass, string $message)

No description

static array
getServiceConditionals(mixed $value)

Returns the Service Conditionals.

static array
getInitializedConditionals(mixed $value)

Returns the initialized conditionals.

static string
hash(mixed $value)

Computes a reasonably unique hash of a value.

Details

at line 160
__construct(ExtensionInterface $extension, ParameterBagInterface $parameterBag = null)

Parameters

ExtensionInterface $extension
ParameterBagInterface $parameterBag

at line 186
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.

Parameters

bool $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.

in Container at line 86
bool isCompiled()

Returns true if the container is compiled.

Return Value

bool

in Container at line 96
ParameterBagInterface getParameterBag()

Gets the service container parameter bag.

Return Value

ParameterBagInterface A ParameterBagInterface instance

in Container at line 110
mixed getParameter(string $name)

Gets a parameter.

Parameters

string $name The parameter name

Return Value

mixed The parameter value

Exceptions

InvalidArgumentException if the parameter is not defined

in Container at line 122
bool hasParameter(string $name)

Checks if a parameter exists.

Parameters

string $name The parameter name

Return Value

bool The presence of parameter in container

in Container at line 133
setParameter(string $name, mixed $value)

Sets a parameter.

Parameters

string $name The parameter name
mixed $value The parameter value

in ContainerBuilder at line 494
set(string $id, object $service)

Sets a service.

Parameters

string $id The service identifier
object $service The service instance

Exceptions

BadMethodCallException When this ContainerBuilder is compiled

in ContainerBuilder at line 528
bool has(string $id)

Returns true if the given service is defined.

Parameters

string $id The service identifier

Return Value

bool true if the service is defined, false otherwise

in ContainerBuilder at line 550
object get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)

Gets a service.

Parameters

string $id The service identifier
int $invalidBehavior The behavior when the service does not exist

Return Value

object The associated service

Exceptions

InvalidArgumentException when no definitions are available
ServiceCircularReferenceException When a circular reference is detected
ServiceNotFoundException When the service is not defined
Exception

See also

Reference

in Container at line 288
bool initialized(string $id)

Returns true if the given service has actually been initialized.

Parameters

string $id

Return Value

bool true if the service has been initialized, false otherwise

in Container at line 304
reset()

Resets shared services from the container.

The container is not intended to be used again after being reset in a normal workflow. This method is meant as a way to release references for ref-counting. A subsequent call to ContainerInterface::get will recreate a new instance of the shared service.

in ContainerBuilder at line 780
array getServiceIds()

Gets all service ids.

Return Value

array An array of all defined service ids

in ContainerBuilder at line 790
array getRemovedIds()

Gets removed service or alias ids.

Return Value

array

in Container at line 347
static string camelize(string $id)

Camelizes a string.

Parameters

string $id A string to camelize

Return Value

string The camelized string

in Container at line 359
static string underscore(string $id)

A string to underscore.

Parameters

string $id The string to underscore

Return Value

string The underscored string

in Container at line 369
protected object load($file)

Creates a service by requiring its factory file.

Parameters

$file

Return Value

object The service created by the file

in ContainerBuilder at line 1528
protected mixed getEnv(string $name)

Fetches a variable from the environment.

Parameters

string $name The name of the environment variable

Return Value

mixed The value to use for the provided environment variable name

Exceptions

EnvNotFoundException When the environment variable is not found and has no default value

in Container at line 421
final protected getService($registry, $id, $method, $load)

Parameters

$registry
$id
$method
$load

in ContainerBuilder at line 164
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.

Parameters

bool $track True if you want to track resources, false otherwise

in ContainerBuilder at line 174
bool isTrackingResources()

Checks if resources are tracked.

Return Value

bool true If resources are tracked, false otherwise

in ContainerBuilder at line 182
setProxyInstantiator(InstantiatorInterface $proxyInstantiator)

Sets the instantiator to be used when fetching proxies.

Parameters

InstantiatorInterface $proxyInstantiator

at line 178
registerExtension(ExtensionInterface $extension)

Parameters

ExtensionInterface $extension

in ContainerBuilder at line 205
ExtensionInterface getExtension(string $name)

Returns an extension by alias or namespace.

Parameters

string $name An alias or a namespace

Return Value

ExtensionInterface An extension instance

Exceptions

LogicException if the extension is not registered

in ContainerBuilder at line 223
ExtensionInterface[] getExtensions()

Returns all registered extensions.

Return Value

ExtensionInterface[] An array of ExtensionInterface

in ContainerBuilder at line 235
bool hasExtension(string $name)

Checks if we have an extension.

Parameters

string $name The name of the extension

Return Value

bool If the extension exists

in ContainerBuilder at line 245
ResourceInterface[] getResources()

Returns an array of resources loaded to build this configuration.

Return Value

ResourceInterface[] An array of resources

in ContainerBuilder at line 253
$this addResource(ResourceInterface $resource)

Parameters

ResourceInterface $resource

Return Value

$this

in ContainerBuilder at line 275
$this setResources(array $resources)

Sets the resources for this configuration.

Parameters

array $resources An array of resources

Return Value

$this

in ContainerBuilder at line 293
$this addObjectResource(object|string $object)

Adds the object class hierarchy as resources.

Parameters

object|string $object An object instance or class name

Return Value

$this

in ContainerBuilder at line 334
ReflectionClass|null getReflectionClass(string|null $class, bool $throw = true)

Retrieves the requested reflection class and registers it for resource tracking.

Parameters

string|null $class
bool $throw

Return Value

ReflectionClass|null

Exceptions

ReflectionException when a parent class/interface/trait is not found and $throw is true

in ContainerBuilder at line 389
bool fileExists(string $path, bool|string $trackContents = true)

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

Parameters

string $path The file or directory path for which to check the existence
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

Return Value

bool

in ContainerBuilder at line 427
$this loadFromExtension(string $extension, array $values = null)

Loads the configuration for an extension.

Parameters

string $extension The extension alias or namespace
array $values An array of values that customizes the extension

Return Value

$this

Exceptions

BadMethodCallException When this ContainerBuilder is compiled
LogicException if the extension is not registered

at line 170
$this addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)

Adds a compiler pass.

Parameters

CompilerPassInterface $pass A compiler pass
string $type The type of compiler pass
int $priority Used to sort the passes

Return Value

$this

in ContainerBuilder at line 467
PassConfig getCompilerPassConfig()

Returns the compiler pass config which can then be modified.

Return Value

PassConfig The compiler pass config

in ContainerBuilder at line 477
Compiler getCompiler()

Returns the compiler.

Return Value

Compiler The compiler

in ContainerBuilder at line 513
removeDefinition(string $id)

Removes a service definition.

Parameters

string $id The service identifier

in ContainerBuilder at line 632
merge(ContainerBuilder $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.

Parameters

ContainerBuilder $container

Exceptions

BadMethodCallException When this ContainerBuilder is compiled

in ContainerBuilder at line 690
array getExtensionConfig(string $name)

Returns the configuration array for the given extension.

Parameters

string $name The name of the extension

Return Value

array An array of configuration

in ContainerBuilder at line 705
prependExtensionConfig(string $name, array $config)

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

Parameters

string $name The name of the extension
array $config The config to set

in ContainerBuilder at line 798
addAliases(array $aliases)

Adds the service aliases.

Parameters

array $aliases

in ContainerBuilder at line 808
setAliases(array $aliases)

Sets the service aliases.

Parameters

array $aliases

in ContainerBuilder at line 825
Alias setAlias(string $alias, string|Alias $id)

Sets an alias for an existing service.

Parameters

string $alias The alias to create
string|Alias $id The service to alias

Return Value

Alias

Exceptions

InvalidArgumentException if the id is not a string or an Alias
InvalidArgumentException if the alias is for itself

in ContainerBuilder at line 849
removeAlias(string $alias)

Removes an alias.

Parameters

string $alias The alias to remove

in ContainerBuilder at line 864
bool hasAlias(string $id)

Returns true if an alias exists under the given identifier.

Parameters

string $id The service identifier

Return Value

bool true if the alias exists, false otherwise

in ContainerBuilder at line 874
Alias[] getAliases()

Gets all defined aliases.

Return Value

Alias[] An array of aliases

in ContainerBuilder at line 888
Alias getAlias(string $id)

Gets an alias.

Parameters

string $id The service identifier

Return Value

Alias An Alias instance

Exceptions

InvalidArgumentException if the alias does not exist

in ContainerBuilder at line 910
Definition register($id, $class = null)

Registers a service definition.

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

Parameters

$id
$class

Return Value

Definition A Definition instance

in ContainerBuilder at line 926
Definition autowire(string $id, string|null $class = null)

Registers an autowired service definition.

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

Parameters

string $id The service identifier
string|null $class The service class

Return Value

Definition The created definition

in ContainerBuilder at line 936
addDefinitions(array $definitions)

Adds the service definitions.

Parameters

array $definitions An array of service definitions

in ContainerBuilder at line 948
setDefinitions(array $definitions)

Sets the service definitions.

Parameters

array $definitions An array of service definitions

in ContainerBuilder at line 959
Definition[] getDefinitions()

Gets all service definitions.

Return Value

Definition[] An array of Definition instances

in ContainerBuilder at line 974
Definition setDefinition(string $id, Definition $definition)

Sets a service definition.

Parameters

string $id The service identifier
Definition $definition A Definition instance

Return Value

Definition the service definition

Exceptions

BadMethodCallException When this ContainerBuilder is compiled

in ContainerBuilder at line 994
bool hasDefinition(string $id)

Returns true if a service definition exists under the given identifier.

Parameters

string $id The service identifier

Return Value

bool true if the service definition exists, false otherwise

in ContainerBuilder at line 1008
Definition getDefinition(string $id)

Gets a service definition.

Parameters

string $id The service identifier

Return Value

Definition A Definition instance

Exceptions

ServiceNotFoundException if the service definition does not exist

in ContainerBuilder at line 1030
Definition findDefinition(string $id)

Gets a service definition by id or alias.

The method "unaliases" recursively to return a Definition instance.

Parameters

string $id The service identifier or alias

Return Value

Definition A Definition instance

Exceptions

ServiceNotFoundException if the service definition does not exist

in ContainerBuilder at line 1179
mixed resolveServices(mixed $value)

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

Parameters

mixed $value A value

Return Value

mixed The same value with all service references replaced by the real service instances and all expressions evaluated

in ContainerBuilder at line 1270
array findTaggedServiceIds(string $name, bool $throwOnAbstract = false)

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'];
    }
}

Parameters

string $name The tag name
bool $throwOnAbstract

Return Value

array An array of tags

in ContainerBuilder at line 1291
array findTags()

Returns all tags the defined services use.

Return Value

array An array of tags

in ContainerBuilder at line 1306
string[] findUnusedTags()

Returns all tags not queried by findTaggedServiceIds.

Return Value

string[] An array of tags

in ContainerBuilder at line 1311
addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider)

in ContainerBuilder at line 1319
ExpressionFunctionProviderInterface[] getExpressionLanguageProviders()

in ContainerBuilder at line 1331
ChildDefinition registerForAutoconfiguration(string $interface)

Returns a ChildDefinition that will be used for autoconfiguring the interface/class.

Parameters

string $interface The class or interface to match

Return Value

ChildDefinition

in ContainerBuilder at line 1348
Alias registerAliasForArgument(string $id, string $type, string $name = null)

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.

Parameters

string $id
string $type
string $name

Return Value

Alias

in ContainerBuilder at line 1364
ChildDefinition[] getAutoconfiguredInstanceof()

Returns an array of ChildDefinition[] keyed by interface.

Return Value

ChildDefinition[]

at line 194
mixed resolveEnvPlaceholders(mixed $value, string|true|null $format = null, array $usedEnvs = null)

Resolves env parameter placeholders in a string or an array.

Parameters

mixed $value The value to resolve
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
array $usedEnvs &$usedEnvs Env vars found while resolving are added to this array

Return Value

mixed The value with env parameters resolved if a string or an array is passed

in ContainerBuilder at line 1441
int[] getEnvCounters()

Get statistics about env usage.

Return Value

int[] The number of time each env vars has been resolved

in ContainerBuilder at line 1458
log(CompilerPassInterface $pass, string $message)

Parameters

CompilerPassInterface $pass
string $message

in ContainerBuilder at line 1472
static array getServiceConditionals(mixed $value)

Returns the Service Conditionals.

Parameters

mixed $value An array of conditionals to return

Return Value

array An array of Service conditionals

in ContainerBuilder at line 1496
static array getInitializedConditionals(mixed $value)

Returns the initialized conditionals.

Parameters

mixed $value An array of conditionals to return

Return Value

array An array of uninitialized conditionals

in ContainerBuilder at line 1518
static string hash(mixed $value)

Computes a reasonably unique hash of a value.

Parameters

mixed $value A serializable value

Return Value

string