ContainerBuilder
class ContainerBuilder extends Container implements TaggedContainerInterface
ContainerBuilder is a DI container that provides an API to easily describe services.
Methods
Compiles the container.
Sets a service.
Returns true if the given service is defined.
Gets a service.
Returns true if the given service has actually been initialized.
Gets all service ids.
Sets the track resources flag.
Checks if resources are tracked.
Sets the instantiator to be used when fetching proxies.
Returns an extension by alias or namespace.
Returns all registered extensions.
Checks if we have an extension.
Returns an array of resources loaded to build this configuration.
Sets the resources for this configuration.
Adds the object class hierarchy as resources.
Loads the configuration for an extension.
Adds a compiler pass.
Returns the compiler pass config which can then be modified.
Returns the compiler.
Removes a service definition.
Merges a ContainerBuilder with the current ContainerBuilder configuration.
Returns the configuration array for the given extension.
Prepends a config array to the configs of the given extension.
Adds the service aliases.
Sets the service aliases.
Removes an alias.
Returns true if an alias exists under the given identifier.
Gets all defined aliases.
Registers a service definition.
Adds the service definitions.
Sets the service definitions.
Gets all service definitions.
Returns true if a service definition exists under the given identifier.
Gets a service definition.
Gets a service definition by id or alias.
Replaces service references by the real service instance and evaluates expressions.
Returns service ids for a given tag.
Returns all tags the defined services use.
Returns all tags not queried by findTaggedServiceIds.
No description
Returns the Service Conditionals.
Details
in Container at line line 78
__construct(ParameterBagInterface $parameterBag = null)
Constructor.
at line line 530
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 line 103
bool
isFrozen()
Returns true if the container parameter bag are frozen.
in Container at line line 113
ParameterBagInterface
getParameterBag()
Gets the service container parameter bag.
in Container at line line 127
mixed
getParameter(string $name)
Gets a parameter.
in Container at line line 139
bool
hasParameter(string $name)
Checks if a parameter exists.
in Container at line line 150
setParameter(string $name, mixed $value)
Sets a parameter.
at line line 341
set(string $id, object $service)
Sets a service.
at line line 384
bool
has(string $id)
Returns true if the given service is defined.
at line line 405
object
get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
Gets a service.
in Container at line line 293
bool
initialized(string $id)
Returns true if the given service has actually been initialized.
in Container at line line 311
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.
at line line 560
array
getServiceIds()
Gets all service ids.
in Container at line line 342
static string
camelize(string $id)
Camelizes a string.
in Container at line line 354
static string
underscore(string $id)
A string to underscore.
at line line 103
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.
at line line 113
bool
isTrackingResources()
Checks if resources are tracked.
at line line 123
setProxyInstantiator(InstantiatorInterface $proxyInstantiator)
Sets the instantiator to be used when fetching proxies.
at line line 133
registerExtension(ExtensionInterface $extension)
Registers an extension.
at line line 151
ExtensionInterface
getExtension(string $name)
Returns an extension by alias or namespace.
at line line 169
ExtensionInterface[]
getExtensions()
Returns all registered extensions.
at line line 181
bool
hasExtension(string $name)
Checks if we have an extension.
at line line 191
ResourceInterface[]
getResources()
Returns an array of resources loaded to build this configuration.
at line line 203
ContainerBuilder
addResource(ResourceInterface $resource)
Adds a resource for this configuration.
at line line 221
ContainerBuilder
setResources(array $resources)
Sets the resources for this configuration.
at line line 239
ContainerBuilder
addObjectResource(object $object)
Adds the object class hierarchy as resources.
at line line 255
ContainerBuilder
addClassResource(ReflectionClass $class)
Adds the given class hierarchy as resources.
at line line 279
ContainerBuilder
loadFromExtension(string $extension, array $values = array())
Loads the configuration for an extension.
at line line 300
ContainerBuilder
addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
Adds a compiler pass.
at line line 314
PassConfig
getCompilerPassConfig()
Returns the compiler pass config which can then be modified.
at line line 324
Compiler
getCompiler()
Returns the compiler.
at line line 372
removeDefinition(string $id)
Removes a service definition.
at line line 460
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 line 492
array
getExtensionConfig(string $name)
Returns the configuration array for the given extension.
at line line 507
prependExtensionConfig(string $name, array $config)
Prepends a config array to the configs of the given extension.
at line line 570
addAliases(array $aliases)
Adds the service aliases.
at line line 582
setAliases(array $aliases)
Sets the service aliases.
at line line 597
setAlias(string $alias, string|Alias $id)
Sets an alias for an existing service.
at line line 621
removeAlias(string $alias)
Removes an alias.
at line line 633
bool
hasAlias(string $id)
Returns true if an alias exists under the given identifier.
at line line 643
Alias[]
getAliases()
Gets all defined aliases.
at line line 657
Alias
getAlias(string $id)
Gets an alias.
at line line 679
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 line 689
addDefinitions(array $definitions)
Adds the service definitions.
at line line 701
setDefinitions(array $definitions)
Sets the service definitions.
at line line 712
Definition[]
getDefinitions()
Gets all service definitions.
at line line 727
Definition
setDefinition(string $id, Definition $definition)
Sets a service definition.
at line line 747
bool
hasDefinition(string $id)
Returns true if a service definition exists under the given identifier.
at line line 761
Definition
getDefinition(string $id)
Gets a service definition.
at line line 783
Definition
findDefinition(string $id)
Gets a service definition by id or alias.
The method "unaliases" recursively to return a Definition instance.
at line line 909
mixed
resolveServices(mixed $value)
Replaces service references by the real service instance and evaluates expressions.
at line line 944
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 line 962
array
findTags()
Returns all tags the defined services use.
at line line 977
string[]
findUnusedTags()
Returns all tags not queried by findTaggedServiceIds.
at line line 982
addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider)
at line line 990
ExpressionFunctionProviderInterface[]
getExpressionLanguageProviders()
at line line 1002
static array
getServiceConditionals(mixed $value)
Returns the Service Conditionals.