Methods |
public
|
__construct()
|
#
|
public
|
unload(): void
Close the object's underlying resources
Close the object's underlying resources
Overriden by
Implements
|
#
|
final
public
static
|
hasGlobalContainer(): bool
Check if the global container is set
Check if the global container is set
Implements
|
#
|
final
public
static
|
getGlobalContainer(): ContainerInterface
Get the global container, creating it if necessary
Get the global container, creating it if necessary
Implements
|
#
|
final
public
static
|
setGlobalContainer(?ContainerInterface $container): void
Set or unset the global container
Set or unset the global container
Implements
|
#
|
final
public
|
get(string $id, array $args = []): object
Finds an entry of the container by its identifier and returns it.
Finds an entry of the container by its identifier and returns it.
Parameters
$id |
Identifier of the entry to look for.
|
Returns
Implements
|
#
|
final
public
|
getAs(string $id, string $service, array $args = []): object
Resolve a partially-resolved service from the container
Resolve a partially-resolved service from the container
This method resolves $id normally but passes $service to
{@see ServiceAwareInterface::setService()} instead of $id .
Implements
|
#
|
final
public
|
getName(string $id): string
Resolve a service to a concrete class name
Resolve a service to a concrete class name
Implements
|
#
|
final
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.
|
Implements
|
#
|
final
public
|
hasSingleton(string $id): bool
Check if a shared service is bound to the container
Check if a shared service is bound to the container
Implements
|
#
|
final
public
|
hasInstance(string $id): bool
Check if a service resolves to a shared instance
Check if a service resolves to a shared instance
Implements
|
#
|
final
public
|
inContextOf(string $id): static
Apply the contextual bindings of a service to a copy of the container
Apply the contextual bindings of a service to a copy of the container
Implements
|
#
|
final
public
|
bind(string $id, ?string $class = null, array $args = []): $this
Bind a service to the container
Bind a service to the container
Subsequent requests for $id resolve to $class .
If $class is null , $id resolves to itself.
$args are merged with $args passed to {@see get()} or {@see getAs()}
when $id resolves to a new instance of $class .
Implements
|
#
|
final
public
|
bindIf(string $id, ?string $class = null, array $args = []): $this
Bind a service to the container if it isn't already bound
Bind a service to the container if it isn't already bound
Implements
|
#
|
final
public
|
singleton(string $id, ?string $class = null, array $args = []): $this
Bind a shared service to the container
Bind a shared service to the container
Subsequent requests for $id resolve to the instance of $class created
when $id is first requested.
Implements
|
#
|
final
public
|
singletonIf(string $id, ?string $class = null, array $args = []): $this
Bind a shared service to the container if it isn't already bound
Bind a shared service to the container if it isn't already bound
Implements
|
#
|
final
public
|
hasProvider(string $id): bool
Check if a service provider is registered with the container
Check if a service provider is registered with the container
Implements
|
#
|
final
public
|
provider(
string $id,
?array $services = null,
array $exceptServices = [],
int $lifetime = ServiceLifetime::INHERIT,
): $this
Register a service provider with the container, optionally specifying
which of its services to bind or ignore
Register a service provider with the container, optionally specifying
which of its services to bind or ignore
For performance reasons, classes bound to the container with
{@see bind()} or {@see singleton()} are not loaded until they are
resolved. Classes registered with {@see provider()} are loaded
immediately, but are not instantiated until they are resolved.
Parameters
$services |
Services to bind, or null to
include all services.
|
$exceptServices |
Services to ignore.
|
Implements
|
#
|
final
public
|
addContextualBinding($context, string $dependency, $value): $this
Register a contextual binding with the container
Register a contextual binding with the container
Subsequent requests from $context for $dependency resolve to
$value .
If $dependency starts with '$' , it is matched with dependencies of
$context by constructor parameter name, otherwise it is matched by
type.
If $value is a callback, its return value is used.
Implements
|
#
|
final
public
|
instance(string $id, $instance): $this
Bind a shared instance to the container
Bind a shared instance to the container
Implements
|
#
|
final
public
|
providers(array $serviceMap, int $lifetime = ServiceLifetime::INHERIT): $this
Register a service map with the container
Register a service map with the container
A service map is an array with entries that map a service (usually an
interface) to a service provider (a class that extends or implements the
service).
Multiple services may be mapped to the same service provider, and service
providers may be mapped to themselves. For example, to make BarClass
discoverable via {@see ContainerInterface::getProviders()} whether it's
bound to a service or not:
<?php
$container->providers([
FooInterface::class => Env::get('foo_provider'),
BarClass::class => BarClass::class,
]);
Implements
|
#
|
final
public
|
getProviders(): array
Get a list of service providers registered with the container
Get a list of service providers registered with the container
Implements
|
#
|
final
public
|
unbind(string $id): $this
Remove a binding from the container
Remove a binding from the container
Implements
|
#
|
final
public
|
removeInstance(string $id): $this
Remove a shared instance from the container
Remove a shared instance from the container
Implements
|
#
|