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. |
|
| Boolean |
initialized(string $id)
Returns true if the given service has actually been initialized |
from Container |
| array |
getServiceIds()
Gets all service ids. |
|
|
enterScope(string $name)
This is called when you enter a scope |
from Container | |
|
leaveScope(string $name)
This is called to leave the current scope, and move back to the parent scope. |
from Container | |
|
addScope(ScopeInterface $scope)
Adds a scope to the container. |
from Container | |
| Boolean |
hasScope(string $name)
Returns whether this container has a certain scope |
from Container |
| Boolean |
isScopeActive(string $name)
Returns whether this 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 |
|
setResourceTracking(Boolean $track)
Sets the track resources flag. |
||
| Boolean |
isTrackingResources()
Checks if resources are tracked. |
|
|
setProxyInstantiator(InstantiatorInterface $proxyInstantiator)
Sets the instantiator to be used when fetching proxies. |
||
|
registerExtension(ExtensionInterface $extension)
Registers an extension. |
||
| ExtensionInterface |
getExtension(string $name)
Returns an extension by alias or namespace. |
|
| ExtensionInterface[] |
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. |
|
| ContainerBuilder |
setResources(array $resources)
Sets the resources for this configuration. |
|
| ContainerBuilder |
addObjectResource(object $object)
Adds the object class hierarchy as resources. |
|
| ContainerBuilder |
addClassResource(ReflectionClass $class)
Adds the given class hierarchy as resources. |
|
| ContainerBuilder |
loadFromExtension(string $extension, array $values = array())
Loads the configuration for an extension. |
|
| ContainerBuilder |
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. |
|
|
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. |
||
| Boolean |
hasAlias(string $id)
Returns true if an alias exists under the given identifier. |
|
| Alias[] |
getAliases()
Gets all defined aliases. |
|
| Alias |
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. |
||
| Definition[] |
getDefinitions()
Gets all service definitions. |
|
| Definition |
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. |
|
| object |
createService(Definition $definition, string $id, Boolean $tryProxy = true)
Creates a service for a service definition. |
|
| mixed |
resolveServices(mixed $value)
Replaces service references by the real service instance. |
|
| array |
findTaggedServiceIds(string $name)
Returns service ids for a given tag. |
|
| array |
findTags()
Returns all tags the defined services use. |
|
| static array |
getServiceConditionals(mixed $value)
Returns the Service Conditionals. |
Details
in Container at line 86
public
__construct(ParameterBagInterface $parameterBag = null)
Constructor.
at line 611
public
compile()
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.
in Container at line 123
public Boolean
isFrozen()
Returns true if the container parameter bag are frozen.
in Container at line 135
public ParameterBagInterface
getParameterBag()
Gets the service container parameter bag.
in Container at line 151
public mixed
getParameter(string $name)
Gets a parameter.
in Container at line 165
public Boolean
hasParameter(string $name)
Checks if a parameter exists.
in Container at line 178
public
setParameter(string $name, mixed $value)
Sets a parameter.
at line 386
public
set(string $id, object $service, string $scope = self::SCOPE_CONTAINER)
Sets a service.
at line 437
public Boolean
has(string $id)
Returns true if the given service is defined.
at line 461
public object
get(string $id, integer $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
Gets a service.
in Container at line 325
public Boolean
initialized(string $id)
Returns true if the given service has actually been initialized
at line 641
public array
getServiceIds()
Gets all service ids.
in Container at line 358
public
enterScope(string $name)
This is called when you enter a scope
in Container at line 406
public
leaveScope(string $name)
This is called to leave the current scope, and move back to the parent scope.
in Container at line 448
public
addScope(ScopeInterface $scope)
Adds a scope to the container.
in Container at line 482
public Boolean
hasScope(string $name)
Returns whether this container has a certain scope
in Container at line 498
public Boolean
isScopeActive(string $name)
Returns whether this scope is currently active
This does not actually check if the passed scope actually exists.
in Container at line 510
static public string
camelize(string $id)
Camelizes a string.
in Container at line 522
static public string
underscore(string $id)
A string to underscore.
at line 89
public
setResourceTracking(Boolean $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.
at line 99
public Boolean
isTrackingResources()
Checks if resources are tracked.
at line 109
public
setProxyInstantiator(InstantiatorInterface $proxyInstantiator)
Sets the instantiator to be used when fetching proxies.
at line 121
public
registerExtension(ExtensionInterface $extension)
Registers an extension.
at line 141
public ExtensionInterface
getExtension(string $name)
Returns an extension by alias or namespace.
at line 161
public ExtensionInterface[]
getExtensions()
Returns all registered extensions.
at line 175
public Boolean
hasExtension(string $name)
Checks if we have an extension.
at line 187
public ResourceInterface[]
getResources()
Returns an array of resources loaded to build this configuration.
at line 201
public ContainerBuilder
addResource(ResourceInterface $resource)
Adds a resource for this configuration.
at line 221
public ContainerBuilder
setResources(array $resources)
Sets the resources for this configuration.
at line 241
public ContainerBuilder
addObjectResource(object $object)
Adds the object class hierarchy as resources.
at line 257
public ContainerBuilder
addClassResource(ReflectionClass $class)
Adds the given class hierarchy as resources.
at line 283
public ContainerBuilder
loadFromExtension(string $extension, array $values = array())
Loads the configuration for an extension.
at line 306
public ContainerBuilder
addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
Adds a compiler pass.
at line 326
public PassConfig
getCompilerPassConfig()
Returns the compiler pass config which can then be modified.
at line 342
public Compiler
getCompiler()
Returns the compiler.
at line 358
public array
getScopes()
Returns all Scopes.
at line 370
public array
getScopeChildren()
Returns all Scope children.
at line 423
public
removeDefinition(string $id)
Removes a service definition.
at line 537
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 571
public array
getExtensionConfig(string $name)
Returns the configuration array for the given extension.
at line 586
public
prependExtensionConfig(string $name, array $config)
Prepends a config array to the configs of the given extension.
at line 653
public
addAliases(array $aliases)
Adds the service aliases.
at line 667
public
setAliases(array $aliases)
Sets the service aliases.
at line 684
public
setAlias(string $alias, string|Alias $id)
Sets an alias for an existing service.
at line 710
public
removeAlias(string $alias)
Removes an alias.
at line 724
public Boolean
hasAlias(string $id)
Returns true if an alias exists under the given identifier.
at line 736
public Alias[]
getAliases()
Gets all defined aliases.
at line 752
public Alias
getAlias(string $id)
Gets an alias.
at line 776
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 788
public
addDefinitions(array $definitions)
Adds the service definitions.
at line 802
public
setDefinitions(array $definitions)
Sets the service definitions.
at line 815
public Definition[]
getDefinitions()
Gets all service definitions.
at line 832
public Definition
setDefinition(string $id, Definition $definition)
Sets a service definition.
at line 854
public Boolean
hasDefinition(string $id)
Returns true if a service definition exists under the given identifier.
at line 870
public Definition
getDefinition(string $id)
Gets a service definition.
at line 894
public Definition
findDefinition(string $id)
Gets a service definition by id or alias.
The method "unaliases" recursively to return a Definition instance.
at line 919
public object
createService(Definition $definition, string $id, Boolean $tryProxy = true)
Creates a service for a service definition.
at line 1002
public mixed
resolveServices(mixed $value)
Replaces service references by the real service instance.
at line 1037
public array
findTaggedServiceIds(string $name)
Returns service ids for a given tag.
Example:
$container->register('foo')->addTag('my.tag', array('hello' => 'world'));
$serviceIds = $container->findTaggedServiceIds('my.tag'); foreach ($serviceIds as $serviceId => $tags) { foreach ($tags as $tag) { echo $tag['hello']; } }
at line 1054
public array
findTags()
Returns all tags the defined services use.
at line 1071
static public array
getServiceConditionals(mixed $value)
Returns the Service Conditionals.