class LegacyServiceInstantiator (View source)

Use the Symfony Dependency Injection Container to instantiate services.

This factory class is used solely for backwards compatability with Drupal modules that still use drush.services.ymls to define Drush Commands, Generators & etc.; this mechanism is deprecated, though. Modules should instead use the static factory create mechanism.

This object is only in scope during bootstrap; see the DrupalBoot8 class. After it has been used there, it is not referenced by any other code.

Properties

protected array $instantiatedDrushServices
protected array $tags

Methods

__construct(ContainerInterface $container, LoggerInterface $logger)

No description

loadServiceFiles(array $serviceFiles)

Instantiate all of the objects declared by drush.services.yml files, and store them internally in this class for later retreival by type.

bool
isValidServiceData(string $serviceFile, array $serviceFileData)

Validate service data before using it.

bool
allServicesHaveClassElement(string $serviceFile, array $services)

Check all elements for required "class" elements.

instantiateServices(array $services)

Given a drush.services.yml file (parsed into an array), instantiate all of the services referenced therein.

object[]
taggedServices(string $tagName)

After instantiateServices() runs, the resulting instantiated service objects can be retrieved via this method.

object
create(string $class, array $arguments, array $calls)

Create one named service.

instantiateObject(string $class, array $arguments)

Instantiate an object with the given arguments.

call(object $object, string $method, array $arguments)

Call a method of an object with the provided arguments.

array
resolveArguments(array $arguments)

Resolve arguments against our containers. Arguments that do not map to one of our containers are returned unchanged.

object
resolveArgument($arg)

Look up one argument in the appropriate container, or return it as-is.

resolveFromContainer(Container $container, string $arg)

Look up in the provided container; throw an exception if not found, unless the service name begins with ? (e.g.

isRequired(string $arg)

Check to see if the provided argument begins with a ?; those that do not are required.

bool
atLeastOneValue($args)

Helper function to determine whether or not any of the arguments resolved. set methods with non-required DI container references are not called at all if the optional references are not in the container.

Details

__construct(ContainerInterface $container, LoggerInterface $logger)

No description

Parameters

ContainerInterface $container
LoggerInterface $logger

loadServiceFiles(array $serviceFiles)

Instantiate all of the objects declared by drush.services.yml files, and store them internally in this class for later retreival by type.

Parameters

array $serviceFiles

List of drush.services.yml files

protected bool isValidServiceData(string $serviceFile, array $serviceFileData)

Validate service data before using it.

Parameters

string $serviceFile

Path to service file being checked

array $serviceFileData

Parsed data from drush.services.yml

Return Value

bool

protected bool allServicesHaveClassElement(string $serviceFile, array $services)

Check all elements for required "class" elements.

Parameters

string $serviceFile

Path to service file being checked

array $services

List of data from 'services' element from drush.services.yml

Return Value

bool

instantiateServices(array $services)

Given a drush.services.yml file (parsed into an array), instantiate all of the services referenced therein.

The services created may be retrieved via the taggedServices() method.

Parameters

array $services

object[] taggedServices(string $tagName)

After instantiateServices() runs, the resulting instantiated service objects can be retrieved via this method.

Parameters

string $tagName

Name of service (e.g. 'drush.command') to retrieve

Return Value

object[]

Command handlers with the specified tag

object create(string $class, array $arguments, array $calls)

Create one named service.

Parameters

string $class

Class containing implementation

array $arguments

Parameters to class constructor

array $calls

Return Value

object

Instantiated command handler from the service file

instantiateObject(string $class, array $arguments)

Instantiate an object with the given arguments.

Arguments are first looked up from the Drupal container or from our dynamic service container if they begin with an @.

Parameters

string $class

Class containing implementation

array $arguments

Parameters to class constructor

call(object $object, string $method, array $arguments)

Call a method of an object with the provided arguments.

Arguments are resolved against the container first.

Parameters

object $object

Command handler to initialize

string $method

Name of method to call

array $arguments

Arguments to pass to class method

protected array resolveArguments(array $arguments)

Resolve arguments against our containers. Arguments that do not map to one of our containers are returned unchanged.

Parameters

array $arguments

Arguments to resolve

Return Value

array

Arguments after they have been resolved by DI container

protected object resolveArgument($arg)

Look up one argument in the appropriate container, or return it as-is.

Parameters

$arg

Return Value

object

Argument after it has been resolved by DI container

protected resolveFromContainer(Container $container, string $arg)

Look up in the provided container; throw an exception if not found, unless the service name begins with ? (e.g.

@?drupal.service or *?drush.service).

Parameters

Container $container

Drupal DI container

string $arg

Argument to resolve

protected isRequired(string $arg)

Check to see if the provided argument begins with a ?; those that do not are required.

Parameters

string $arg

protected bool atLeastOneValue($args)

Helper function to determine whether or not any of the arguments resolved. set methods with non-required DI container references are not called at all if the optional references are not in the container.

Parameters

$args

Return Value

bool

True if at least one argument is not empty