| Methods |
public
|
__construct(ParameterBagInterface $parameterBag = null)
|
#
|
public
|
setResourceTracking(bool $track): void
Sets the track resources flag.
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
|
isTrackingResources(): bool
Checks if resources are tracked.
Checks if resources are tracked.
|
#
|
public
|
setProxyInstantiator(InstantiatorInterface $proxyInstantiator): void
Sets the instantiator to be used when fetching proxies.
Sets the instantiator to be used when fetching proxies.
|
#
|
public
|
registerExtension(ExtensionInterface $extension): void
|
#
|
public
|
getExtension(string $name): ExtensionInterface
Returns an extension by alias or namespace.
Returns an extension by alias or namespace.
Throws
|
#
|
public
|
getExtensions(): array<string, ExtensionInterface>
Returns all registered extensions.
Returns all registered extensions.
|
#
|
public
|
hasExtension(string $name): bool
Checks if we have an extension.
Checks if we have an extension.
|
#
|
public
|
getResources(): ResourceInterface[]
Returns an array of resources loaded to build this configuration.
Returns an array of resources loaded to build this configuration.
|
#
|
public
|
addResource(ResourceInterface $resource): $this
|
#
|
public
|
setResources(array<string, ResourceInterface> $resources): $this
Sets the resources for this configuration.
Sets the resources for this configuration.
|
#
|
public
|
addObjectResource(object|string $object): $this
Adds the object class hierarchy as resources.
Adds the object class hierarchy as resources.
Parameters
| $object |
An object instance or class name
|
|
#
|
public
|
getReflectionClass(?string $class, bool $throw = true): ?ReflectionClass
Retrieves the requested reflection class and registers it for resource tracking.
Retrieves the requested reflection class and registers it for resource tracking.
Throws
|
#
|
public
|
fileExists(string $path, bool|string $trackContents = true): bool
Checks whether the requested file or directory exists and registers the result for resource tracking.
Checks whether the requested file or directory exists and registers the result for resource tracking.
Parameters
| $path |
The file or directory path for which to check the existence
|
| $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
|
|
#
|
public
|
loadFromExtension(string $extension, array<string, mixed>|null $values = null): $this
Loads the configuration for an extension.
Loads the configuration for an extension.
Parameters
| $extension |
The extension alias or namespace
|
| $values |
An array of values that customizes the extension
|
Throws
|
#
|
public
|
addCompilerPass(
CompilerPassInterface $pass,
string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION,
int $priority = 0,
): $this
Adds a compiler pass.
Parameters
| $type |
The type of compiler pass
|
| $priority |
Used to sort the passes
|
Overriden by
|
#
|
public
|
getCompilerPassConfig(): PassConfig
Returns the compiler pass config which can then be modified.
Returns the compiler pass config which can then be modified.
|
#
|
public
|
getCompiler(): Compiler
Returns the compiler.
|
#
|
public
|
set(string $id, ?object $service): void
Sets a service.
Throws
Overrides
Implements
|
#
|
public
|
removeDefinition(string $id): void
Removes a service definition.
Removes a service definition.
|
#
|
public
|
has(string $id): bool
Returns true if the container can return an entry for the given identifier.
Returns false otherwise.
Returns true if the container can return an entry for the given identifier.
Returns false otherwise.
has($id) returning true does not mean that get($id) will not throw an exception.
It does however mean that get($id) will not throw a NotFoundExceptionInterface.
Parameters
| $id |
Identifier of the entry to look for.
|
Overrides
Implements
|
#
|
public
|
get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object
Gets a service.
Parameters
| $id |
Identifier of the entry to look for.
|
Returns
Throws
Overrides
Implements
|
#
|
private
|
doGet(
string $id,
int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
array &$inlineServices = null,
bool $isConstructorArgument = false,
): mixed
|
#
|
public
|
merge(self $container): void
Merges a ContainerBuilder with the current ContainerBuilder configuration.
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
|
#
|
public
|
getExtensionConfig(string $name): array<array<string, mixed>>
Returns the configuration array for the given extension.
Returns the configuration array for the given extension.
|
#
|
public
|
prependExtensionConfig(string $name, array<string, mixed> $config): void
Prepends a config array to the configs of the given extension.
Prepends a config array to the configs of the given extension.
|
#
|
public
|
deprecateParameter(
string $name,
string $package,
string $version,
string $message = 'The parameter "%s" is deprecated.',
): void
Deprecates a service container parameter.
Deprecates a service container parameter.
Throws
|
#
|
public
|
compile(bool $resolveEnvPlaceholders = false): void
Compiles the container.
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
| $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.
|
Overrides
Overriden by
|
#
|
public
|
getServiceIds(): array
Gets all service ids.
|
#
|
public
|
getRemovedIds(): array<string, bool>
Gets removed service or alias ids.
Gets removed service or alias ids.
Overrides
|
#
|
public
|
addAliases(array<string, string|Alias> $aliases): void
Adds the service aliases.
Adds the service aliases.
|
#
|
public
|
setAliases(array<string, string|Alias> $aliases): void
Sets the service aliases.
Sets the service aliases.
|
#
|
public
|
setAlias(string $alias, string|Alias $id): Alias
Sets an alias for an existing service.
Sets an alias for an existing service.
Throws
|
#
|
public
|
removeAlias(string $alias): void
|
#
|
public
|
hasAlias(string $id): bool
|
#
|
public
|
getAliases(): array<string, Alias>
|
#
|
public
|
getAlias(string $id): Alias
|
#
|
public
|
register(string $id, string $class = null): Definition
Registers a service definition.
Registers a service definition.
This methods allows for simple registration of service definition
with a fluid interface.
|
#
|
public
|
autowire(string $id, string $class = null): Definition
Registers an autowired service definition.
Registers an autowired service definition.
This method implements a shortcut for using setDefinition() with
an autowired definition.
|
#
|
public
|
addDefinitions(array<string, Definition> $definitions): void
Adds the service definitions.
Adds the service definitions.
|
#
|
public
|
setDefinitions(array<string, Definition> $definitions): void
Sets the service definitions.
Sets the service definitions.
|
#
|
public
|
getDefinitions(): array<string, Definition>
Gets all service definitions.
Gets all service definitions.
|
#
|
public
|
setDefinition(string $id, Definition $definition): Definition
Sets a service definition.
Sets a service definition.
Throws
|
#
|
public
|
hasDefinition(string $id): bool
Returns true if a service definition exists under the given identifier.
Returns true if a service definition exists under the given identifier.
|
#
|
public
|
getDefinition(string $id): Definition
Gets a service definition.
Gets a service definition.
Throws
|
#
|
public
|
findDefinition(string $id): Definition
Gets a service definition by id or alias.
Gets a service definition by id or alias.
The method "unaliases" recursively to return a Definition instance.
Throws
|
#
|
private
|
createService(
Definition $definition,
array &$inlineServices,
bool $isConstructorArgument = false,
string $id = null,
bool|object $tryProxy = true,
): mixed
Creates a service for a service definition.
Creates a service for a service definition.
Throws
|
#
|
public
|
resolveServices(mixed $value): mixed
Replaces service references by the real service instance and evaluates expressions.
Replaces service references by the real service instance and evaluates expressions.
Returns
The same value with all service references replaced by
the real service instances and all expressions evaluated
|
#
|
private
|
doResolveServices(mixed $value, array &$inlineServices = [], bool $isConstructorArgument = false): mixed
|
#
|
public
|
findTaggedServiceIds(string $name, bool $throwOnAbstract = false): array<string, array>
Returns service ids for a given tag.
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
Returns
An array of tags with the tagged service as key, holding a list of attribute arrays
Implements
|
#
|
public
|
findTags(): string[]
Returns all tags the defined services use.
Returns all tags the defined services use.
|
#
|
public
|
findUnusedTags(): string[]
Returns all tags not queried by findTaggedServiceIds.
Returns all tags not queried by findTaggedServiceIds.
|
#
|
public
|
addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider): void
|
#
|
public
|
getExpressionLanguageProviders(): ExpressionFunctionProviderInterface[]
|
#
|
public
|
registerForAutoconfiguration(string $interface): ChildDefinition
Returns a ChildDefinition that will be used for autoconfiguring the interface/class.
Returns a ChildDefinition that will be used for autoconfiguring the interface/class.
|
#
|
public
|
registerAttributeForAutoconfiguration<T>(
class-string<T> $attributeClass,
callable(ChildDefinition, T, Reflector): void $configurator,
): void
Registers an attribute that will be used for autoconfiguring annotated classes.
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.
|
#
|
public
|
registerAliasForArgument(string $id, string $type, string $name = null): Alias
Registers an autowiring alias that only binds to a specific argument name.
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
|
getAutoconfiguredInstanceof(): array<string, ChildDefinition>
Returns an array of ChildDefinition[] keyed by interface.
Returns an array of ChildDefinition[] keyed by interface.
|
#
|
public
|
getAutoconfiguredAttributes(): array<string, callable>
|
#
|
public
|
resolveEnvPlaceholders(mixed $value, string|true|null $format = null, array &$usedEnvs = null): mixed
Resolves env parameter placeholders in a string or an array.
Resolves env parameter placeholders in a string or an array.
Parameters
| $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
|
| $usedEnvs |
Env vars found while resolving are added to this array
|
Returns
The value with env parameters resolved if a string or an array is passed
Overriden by
|
#
|
public
|
getEnvCounters(): int[]
Get statistics about env usage.
Get statistics about env usage.
Returns
The number of time each env vars has been resolved
|
#
|
public
|
log(CompilerPassInterface $pass, string $message): void
|
#
|
final
public
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.
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
|
#
|
public
static
|
hash(mixed $value): string
Computes a reasonably unique hash of a serializable value.
Computes a reasonably unique hash of a serializable value.
|
#
|
protected
|
getEnv(string $name): mixed
Fetches a variable from the environment.
Fetches a variable from the environment.
Overrides
|
#
|
private
|
callMethod(object $service, array $call, array &$inlineServices): mixed
|
#
|
private
|
shareService(Definition $definition, mixed $service, ?string $id, array &$inlineServices): void
|
#
|
private
|
getExpressionLanguage(): ExpressionLanguage
|
#
|
private
|
inVendors(string $path): bool
|
#
|