class ContainerBuilder extends Container implements TaggedContainerInterface
ContainerBuilder is a DI container that provides an API to easily describe services.
Methods
|
__construct(ParameterBagInterface $parameterBag = null)
Constructor. |
from Container | |
|
compile()
Compiles the container. |
||
| Boolean |
isFrozen()
Returns true if the container parameter bag are frozen. |
from Container |
| ParameterBagInterface |
getParameterBag()
Gets the service container parameter bag. |
from Container |
| mixed |
getParameter(string $name)
Gets a parameter. |
from Container |
| Boolean |
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, string $scope = self::SCOPE_CONTAINER)
Sets a service. |
||
| Boolean |
has(string $id)
Returns true if the given service is defined. |
|
| object |
get(string $id, integer $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
Gets a service. |
|
| array |
getServiceIds()
Gets all service ids. |
|
| void |
enterScope(string $name)
Enters the given scope |
from Container |
| void |
leaveScope(string $name)
Leaves the current scope, and re-enters the parent scope |
from Container |
| void |
addScope(ScopeInterface $scope)
Adds a scope to the container |
from Container |
| Boolean |
hasScope(string $name)
Whether this container has the given scope |
from Container |
| Boolean |
isScopeActive(string $name)
Determines whether the given scope is currently active. |
from Container |
| static string |
camelize(string $id)
Camelizes a string. |
from Container |
| static string |
underscore(string $id)
A string to underscore. |
from Container |
|
registerExtension(ExtensionInterface $extension)
Registers an extension. |
||
| ExtensionInterface |
getExtension(string $name)
Returns an extension by alias or namespace. |
|
| array |
getExtensions()
Returns all registered extensions. |
|
| Boolean |
hasExtension(string $name)
Checks if we have an extension. |
|
| ResourceInterface[] |
getResources()
Returns an array of resources loaded to build this configuration. |
|
| ContainerBuilder |
addResource(ResourceInterface $resource)
Adds a resource for this configuration. |
|
|
addObjectResource(object $object)
Adds the object class hierarchy as resources. |
||
| ContainerBuilder |
loadFromExtension(string $extension, array $values = array())
Loads the configuration for an extension. |
|
|
addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
Adds a compiler pass. |
||
| PassConfig |
getCompilerPassConfig()
Returns the compiler pass config which can then be modified. |
|
| Compiler |
getCompiler()
Returns the compiler. |
|
| array |
getScopes()
Returns all Scopes. |
|
| array |
getScopeChildren()
Returns all Scope children. |
|
|
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. |
|
|
addAliases(array $aliases)
Adds the service aliases. |
||
|
setAliases(array $aliases)
Sets the service aliases. |
||
|
setAlias(string $alias, mixed $id)
Sets an alias for an existing service. |
||
|
removeAlias(string $alias)
Removes an alias. |
||
| Boolean |
hasAlias(string $id)
Returns true if an alias exists under the given identifier. |
|
| array |
getAliases()
Gets all defined aliases. |
|
| string |
getAlias(string $id)
Gets an alias. |
|
| Definition |
register(string $id, string $class = null)
Registers a service definition. |
|
|
addDefinitions(array $definitions)
Adds the service definitions. |
||
|
setDefinitions(array $definitions)
Sets the service definitions. |
||
| array |
getDefinitions()
Gets all service definitions. |
|
|
setDefinition(string $id, Definition $definition)
Sets a service definition. |
||
| Boolean |
hasDefinition(string $id)
Returns true if a service definition exists under the given identifier. |
|
| Definition |
getDefinition(string $id)
Gets a service definition. |
|
| Definition |
findDefinition(string $id)
Gets a service definition by id or alias. |
|
| mixed |
resolveServices(mixed $value)
Replaces service references by the real service instance. |
|
| array |
findTaggedServiceIds(string $name)
Returns service ids for a given tag. |
|
| static array |
getServiceConditionals(mixed $value)
Returns the Service Conditionals. |
Details
in Container at line 77
public
__construct(ParameterBagInterface $parameterBag = null)
Constructor.
at line 427
public
compile()
Compiles the container.
This method does two things:
* Parameter values are resolved;
* The parameter bag is frozen.
in Container at line 114
public Boolean
isFrozen()
Returns true if the container parameter bag are frozen.
in Container at line 126
public ParameterBagInterface
getParameterBag()
Gets the service container parameter bag.
in Container at line 142
public mixed
getParameter(string $name)
Gets a parameter.
in Container at line 156
public Boolean
hasParameter(string $name)
Checks if a parameter exists.
in Container at line 169
public
setParameter(string $name, mixed $value)
Sets a parameter.
at line 255
public
set(string $id, object $service, string $scope = self::SCOPE_CONTAINER)
Sets a service.
at line 289
public Boolean
has(string $id)
Returns true if the given service is defined.
at line 311
public object
get(string $id, integer $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
Gets a service.
at line 449
public array
getServiceIds()
Gets all service ids.
in Container at line 294
public void
enterScope(string $name)
Enters the given scope
in Container at line 342
public void
leaveScope(string $name)
Leaves the current scope, and re-enters the parent scope
in Container at line 381
public void
addScope(ScopeInterface $scope)
Adds a scope to the container
in Container at line 415
public Boolean
hasScope(string $name)
Whether this container has the given scope
in Container at line 431
public Boolean
isScopeActive(string $name)
Determines whether the given scope is currently active.
It does however not check if the scope actually exists.
in Container at line 443
static public string
camelize(string $id)
Camelizes a string.
in Container at line 455
static public string
underscore(string $id)
A string to underscore.
at line 46
public
registerExtension(ExtensionInterface $extension)
Registers an extension.
at line 64
public ExtensionInterface
getExtension(string $name)
Returns an extension by alias or namespace.
at line 84
public array
getExtensions()
Returns all registered extensions.
at line 98
public Boolean
hasExtension(string $name)
Checks if we have an extension.
at line 110
public ResourceInterface[]
getResources()
Returns an array of resources loaded to build this configuration.
at line 124
public ContainerBuilder
addResource(ResourceInterface $resource)
Adds a resource for this configuration.
at line 138
public
addObjectResource(object $object)
Adds the object class hierarchy as resources.
at line 156
public ContainerBuilder
loadFromExtension(string $extension, array $values = array())
Loads the configuration for an extension.
at line 177
public
addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
Adds a compiler pass.
at line 195
public PassConfig
getCompilerPassConfig()
Returns the compiler pass config which can then be modified.
at line 211
public Compiler
getCompiler()
Returns the compiler.
at line 227
public array
getScopes()
Returns all Scopes.
at line 239
public array
getScopeChildren()
Returns all Scope children.
at line 275
public
removeDefinition(string $id)
Removes a service definition.
at line 370
public
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(array('foo' => 'bar'));
$loader = new LoaderXXX($container);
$loader->load('resource_name');
$container->register('foo', new 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.
at line 402
public array
getExtensionConfig(string $name)
Returns the configuration array for the given extension.
at line 461
public
addAliases(array $aliases)
Adds the service aliases.
at line 475
public
setAliases(array $aliases)
Sets the service aliases.
at line 489
public
setAlias(string $alias, mixed $id)
Sets an alias for an existing service.
at line 515
public
removeAlias(string $alias)
Removes an alias.
at line 529
public Boolean
hasAlias(string $id)
Returns true if an alias exists under the given identifier.
at line 541
public array
getAliases()
Gets all defined aliases.
at line 557
public string
getAlias(string $id)
Gets an alias.
at line 581
public Definition
register(string $id, string $class = null)
Registers a service definition.
This methods allows for simple registration of service definition
with a fluid interface.
at line 593
public
addDefinitions(array $definitions)
Adds the service definitions.
at line 607
public
setDefinitions(array $definitions)
Sets the service definitions.
at line 620
public array
getDefinitions()
Gets all service definitions.
at line 635
public
setDefinition(string $id, Definition $definition)
Sets a service definition.
at line 657
public Boolean
hasDefinition(string $id)
Returns true if a service definition exists under the given identifier.
at line 673
public Definition
getDefinition(string $id)
Gets a service definition.
at line 697
public Definition
findDefinition(string $id)
Gets a service definition by id or alias.
The method "unaliases" recursively to return a Definition instance.
at line 797
public mixed
resolveServices(mixed $value)
Replaces service references by the real service instance.
at line 821
public array
findTaggedServiceIds(string $name)
Returns service ids for a given tag.
at line 840
static public array
getServiceConditionals(mixed $value)
Returns the Service Conditionals.