class Container

The dependency injection container default implementation.

Properties

array deprecated $parameters
protected string[] $aliases
protected array[] $tags
protected array[] $wiring

Methods

__construct(array $params = [])

No description

array
getParameters()

No description

mixed
getParameter(string|int $key)

No description

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)

Does the service exist?

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.

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 55
array getParameters()

No description

Return Value

array

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

No description

Parameters

string|int $key

Return Value

mixed

at line 70
protected array getStaticParameters()

No description

Return Value

array

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

No description

Parameters

string|int $key

Return Value

mixed

at line 86
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 125
void removeService(string $name)

Removes a service instance from the container.

Parameters

string $name

Return Value

void

at line 136
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 155
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 165
string getServiceType(string $name)

Returns type of the service.

Parameters

string $name

Return Value

string

Exceptions

MissingServiceException

at line 186
bool hasService(string $name)

Does the service exist?

Parameters

string $name

Return Value

bool

at line 196
bool isCreated(string $name)

Has a service instance been created?

Parameters

string $name

Return Value

bool

at line 211
object createService(string $name)

Creates new instance of the service.

Parameters

string $name

Return Value

object

Exceptions

MissingServiceException

at line 241
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 271
array findAutowired(string $type)

internal  
 

Returns the names of autowired services of the given type.

Parameters

string $type

Return Value

array

at line 282
array findByType(string $type)

Returns the names of all services of the given type.

Parameters

string $type

Return Value

array

at line 295
array findByTag(string $tag)

Returns the names of services with the given tag.

Parameters

string $tag

Return Value

array

of [service name => tag attributes]

at line 324
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 344
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 353
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 370
final static string getMethodName(string $name)

Returns the method name for creating a service.

Parameters

string $name

Return Value

string

at line 380
void initialize()

No description

Return Value

void