class Container

The dependency injection container default implementation.

Properties

array deprecated $parameters
protected string[] $aliases
protected array<string,array<string,mixed>> $tags
protected array<class-string,array<int,list<string>>> $wiring

Methods

__construct(array $params = [])

No description

array
getParameters()

No description

mixed
getParameter(string|int $key)

Returns a parameter value, loading it dynamically if not yet initialized.

array
getStaticParameters()

No description

mixed
getDynamicParameter(string|int $key)

No description

addService(string $name, object $service)

Adds the service or its factory to the container.

void
removeService(string $name)

Removes a service instance from the container.

object
getService(string $name)

Returns the service instance. If it has not been created yet, it creates it.

object
getByName(string $name)

Returns the service instance. If it has not been created yet, it creates it.

string
getServiceType(string $name)

Returns type of the service.

bool
hasService(string $name)

Checks whether the service exists in the container.

bool
isCreated(string $name)

Has a service instance been created?

object
createService(string $name)

Creates new instance of the service.

object|null
getByType(string $type, bool $throw = true)

Returns an instance of the autowired service of the given type. If it has not been created yet, it creates it.

array
findAutowired(string $type)

Returns the names of autowired services of the given type.

array
findByType(string $type)

Returns the names of all services of the given type.

array
findByTag(string $tag)

Returns the names of services with the given tag.

array
getServiceTypes()

Returns all registered services as a map of service name to type.

array
getAliases()

Returns the alias map: alias name => canonical service name.

array
getInstantiatedServices()

Returns services that have already been instantiated, indexed by service name.

array
getServiceTags(string $name)

Returns the tags attached to the given service.

object
createInstance(string $class, array $args = [])

Creates an instance of the class and passes dependencies to the constructor using autowiring.

void
callInjects(object $service)

Calls all methods starting with 'inject' and passes dependencies to them via autowiring.

mixed
callMethod(callable $function, array $args = [])

Calls the method and passes dependencies to it via autowiring.

static string
getMethodName(string $name)

Returns the method name for creating a service.

void
initialize()

No description

Details

at line 48
__construct(array $params = [])

No description

Parameters

array $params

at line 56
array getParameters()

No description

Return Value

array

at line 65
mixed getParameter(string|int $key)

Returns a parameter value, loading it dynamically if not yet initialized.

Parameters

string|int $key

Return Value

mixed

at line 75
protected array getStaticParameters()

No description

Return Value

array

at line 81
protected mixed getDynamicParameter(string|int $key)

No description

Parameters

string|int $key

Return Value

mixed

at line 91
Container addService(string $name, object $service)

Adds the service or its factory to the container.

Parameters

string $name
object $service

service or its factory

Return Value

Container

at line 130
void removeService(string $name)

Removes a service instance from the container.

Parameters

string $name

Return Value

void

at line 141
object getService(string $name)

Returns the service instance. If it has not been created yet, it creates it.

Parameters

string $name

Return Value

object

Exceptions

MissingServiceException

at line 160
object getByName(string $name)

Returns the service instance. If it has not been created yet, it creates it.

Alias for getService().

Parameters

string $name

Return Value

object

Exceptions

MissingServiceException

at line 171
string getServiceType(string $name)

Returns type of the service.

Parameters

string $name

Return Value

string

Exceptions

MissingServiceException

at line 192
bool hasService(string $name)

Checks whether the service exists in the container.

Parameters

string $name

Return Value

bool

at line 202
bool isCreated(string $name)

Has a service instance been created?

Parameters

string $name

Return Value

bool

at line 217
object createService(string $name)

Creates new instance of the service.

Parameters

string $name

Return Value

object

Exceptions

MissingServiceException

at line 247
object|null getByType(string $type, bool $throw = true)

Returns an instance of the autowired service of the given type. If it has not been created yet, it creates it.

Parameters

string $type
bool $throw

Return Value

object|null

Exceptions

MissingServiceException

at line 277
array findAutowired(string $type)

Returns the names of autowired services of the given type.

Parameters

string $type

Return Value

array

at line 289
array findByType(string $type)

Returns the names of all services of the given type.

Parameters

string $type

Return Value

array

at line 302
array findByTag(string $tag)

Returns the names of services with the given tag.

Parameters

string $tag

Return Value

array

service name => tag value

at line 313
array getServiceTypes()

Returns all registered services as a map of service name to type.

Aliases are not included — use getAliases() separately.

Return Value

array

at line 333
array getAliases()

Returns the alias map: alias name => canonical service name.

Return Value

array

at line 343
array getInstantiatedServices()

Returns services that have already been instantiated, indexed by service name.

Return Value

array

at line 353
array getServiceTags(string $name)

Returns the tags attached to the given service.

Parameters

string $name

Return Value

array

tag name => tag value

at line 394
object createInstance(string $class, array $args = [])

Creates an instance of the class and passes dependencies to the constructor using autowiring.

Parameters

string $class
array $args

Return Value

object

at line 414
void callInjects(object $service)

Calls all methods starting with 'inject' and passes dependencies to them via autowiring.

Parameters

object $service

Return Value

void

at line 424
mixed callMethod(callable $function, array $args = [])

Calls the method and passes dependencies to it via autowiring.

Parameters

callable $function
array $args

Return Value

mixed

at line 445
final static string getMethodName(string $name)

Returns the method name for creating a service.

Parameters

string $name

Return Value

string

at line 455
void initialize()

No description

Return Value

void