class Container extends Container (View source)

Extends the Drupal container to set the service ID on the created object.

Properties

protected array $parameters

The parameters of the container.

from  Container
protected array $aliases

The aliases of the container.

from  Container
protected array $serviceDefinitions

The service definitions of the container.

from  Container
protected array $services

The instantiated services.

from  Container
protected array $privateServices

The instantiated private services.

from  Container
protected array $loading

The currently loading services.

from  Container
protected bool $frozen

Whether the container parameters can still be changed.

from  Container

Methods

__construct(array $container_definition = [])

Constructs a new Container instance.

get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)

{@inheritdoc}

reset()

Resets shared services from the container.

object
createService(array $definition, string $id)

Creates a service from a service definition.

set($id, $service)

{@inheritdoc}

has($id)

{@inheritdoc}

getParameter($name)

{@inheritdoc}

hasParameter($name)

{@inheritdoc}

setParameter($name, $value)

{@inheritdoc}

initialized($id)

{@inheritdoc}

array
resolveServicesAndParameters(array|object $arguments)

Resolves arguments that represent services or variables to the real values.

string[]
getAlternatives(string $search_key, array $keys)

Provides alternatives for a given array and key.

string[]
getServiceAlternatives(string $id)

Provides alternatives in case a service was not found.

string[]
getParameterAlternatives(string $name)

Provides alternatives in case a parameter was not found.

array
getServiceIds()

Gets all defined service IDs.

__sleep()

{@inheritdoc}

Details

__construct(array $container_definition = [])

Constructs a new Container instance.

Parameters

array $container_definition

An array containing the following keys:

  • aliases: The aliases of the container.
  • parameters: The parameters of the container.
  • services: The service definitions of the container.
  • frozen: Whether the container definition came from a frozen container builder or not.
  • machine_format: Whether this container definition uses the optimized machine-readable container format.

get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)

{@inheritdoc}

Parameters

$id
$invalid_behavior

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.

protected object createService(array $definition, string $id)

Creates a service from a service definition.

Parameters

array $definition

The service definition to create a service from.

string $id

The service identifier, necessary so it can be shared if its public.

Return Value

object

The service described by the service definition.

Exceptions

RuntimeException
InvalidArgumentException
ReflectionException

set($id, $service)

{@inheritdoc}

Parameters

$id
$service

has($id)

{@inheritdoc}

Parameters

$id

getParameter($name)

{@inheritdoc}

Parameters

$name

hasParameter($name)

{@inheritdoc}

Parameters

$name

setParameter($name, $value)

{@inheritdoc}

Parameters

$name
$value

initialized($id)

{@inheritdoc}

Parameters

$id

protected array resolveServicesAndParameters(array|object $arguments)

Resolves arguments that represent services or variables to the real values.

Parameters

array|object $arguments

The arguments to resolve.

Return Value

array

The resolved arguments.

Exceptions

RuntimeException
InvalidArgumentException

protected string[] getAlternatives(string $search_key, array $keys)

Provides alternatives for a given array and key.

Parameters

string $search_key

The search key to get alternatives for.

array $keys

The search space to search for alternatives in.

Return Value

string[]

An array of strings with suitable alternatives.

protected string[] getServiceAlternatives(string $id)

Provides alternatives in case a service was not found.

Parameters

string $id

The service to get alternatives for.

Return Value

string[]

An array of strings with suitable alternatives.

protected string[] getParameterAlternatives(string $name)

Provides alternatives in case a parameter was not found.

Parameters

string $name

The parameter to get alternatives for.

Return Value

string[]

An array of strings with suitable alternatives.

array getServiceIds()

Gets all defined service IDs.

Return Value

array

An array of all defined service IDs.

__sleep()

{@inheritdoc}