class ServiceManager (View source)

Manage Drush services.

This class manages the various services / plugins supported by Drush. The primary examples of these include:

  • Command files
  • Hooks
  • Symfony Console commands
  • Command info alterers
  • Generators

Most services are discovered via the PSR-4 discovery mechanism. Legacy services are injected into this object by the bootstrap handler (DrushBoot8) using the LegacyServiceFinder and LegacyServiceInstantiator classes.

Properties

protected string[] $bootstrapCommandClasses

Methods

__construct(ClassLoader $autoloader, DrushConfig $config, LoggerInterface $logger)

No description

void
loadCommandClasses(array $commandClasses)

Ensure that any discovered class that is not part of the autoloader is, in fact, included.

array
bootstrapCommandClasses()

Return cached of deferred commandhander objects.

array
discover(array $commandfileSearchpath, string $baseNamespace)

Discover all of the different kinds of command handler objects in the places where Drush can find them. Called during preflight; some command classes are returned right away, and others are saved to be handled later during Drupal bootstrap.

array
discoverCommandsFromConfiguration()

Discover commands explicitly declared in configuration.

array
discoverCommands(array $directoryList, string $baseNamespace)

Discovers command classes from a provided search path.

array
discoverPsr4Commands()

Discover PSR-4 autoloaded classes that implement Annotated Command library command handlers.

array
discoverPsr4Generators()

Discover PSR-4 autoloaded classes that implement DCG generators.

array
discoverModuleCommands(array $directoryList, string $baseNamespace)

Discover module commands. This is the preferred way to find module commands in Drush 12+.

array
discoverModuleCommandInfoAlterers(array $directoryList, string $baseNamespace)

Discover command info alterers in modules.

array
instantiateYamlCliCommands()

Instantiate commands from Grasmash\YamlCli that we want to expose as Drush commands.

array
instantiateServices(array $bootstrapCommandClasses, ContainerInterface $drushContainer, ContainerInterface|null $container = null)

Instantiate objects given a lsit of classes. For each class, if it has a static create factory, use that to instantiate it, passing both the Drupal and Drush DI containers. If there is no static factory, then instantiate it via 'new $class'

bool
supportsCompoundContainer($class, $drush_container)

Determine if the first parameter of the create method supports our container with delegate.

bool
hasStaticCreateFactory(string $class)

Check to see if the provided class has a static create method.

int|null
bootStrapAttributeValue(string $class)

No description

bool
requiresBootstrap(string $class)

Check whether a command class requires Drupal bootstrap.

bool
hasStaticCreateEarlyFactory(string $class)

Check to see if the provided class has a static createEarly method.

bool
hasStaticMethod(string $class, string $methodName)

Check to see if the provided class has the specified static method.

array
discoverModuleGenerators(array $directoryList, string $baseNamespace)

Return generators that ship in modules.

void
inflect(ContainerInterface $container, mixed $object)

Inject any dependencies needed via the "*AwareInterface" pattern

Details

__construct(ClassLoader $autoloader, DrushConfig $config, LoggerInterface $logger)

No description

Parameters

ClassLoader $autoloader
DrushConfig $config
LoggerInterface $logger

protected void loadCommandClasses(array $commandClasses)

Ensure that any discovered class that is not part of the autoloader is, in fact, included.

Parameters

array $commandClasses

Return Value

void

array bootstrapCommandClasses()

Return cached of deferred commandhander objects.

Return Value

array

List of class names to instantiate at bootstrap time.

array discover(array $commandfileSearchpath, string $baseNamespace)

Discover all of the different kinds of command handler objects in the places where Drush can find them. Called during preflight; some command classes are returned right away, and others are saved to be handled later during Drupal bootstrap.

Parameters

array $commandfileSearchpath

List of directories to search

string $baseNamespace

The namespace to use at the base of each search diretory. Namespace components mirror directory structure.

Return Value

array

List of command classes

array discoverCommandsFromConfiguration()

Discover commands explicitly declared in configuration.

Return Value

array

List of command classes

array discoverCommands(array $directoryList, string $baseNamespace)

Discovers command classes from a provided search path.

Parameters

array $directoryList

List of directories to search

string $baseNamespace

The namespace to use at the base of each search directory. Namespace components mirror directory structure.

Return Value

array

List of command classes

array discoverPsr4Commands()

Discover PSR-4 autoloaded classes that implement Annotated Command library command handlers.

Return Value

array

List of command classes

array discoverPsr4Generators()

Discover PSR-4 autoloaded classes that implement DCG generators.

Return Value

array

List of generator classes

array discoverModuleCommands(array $directoryList, string $baseNamespace)

Discover module commands. This is the preferred way to find module commands in Drush 12+.

Parameters

array $directoryList
string $baseNamespace

Return Value

array

List of command classes

array discoverModuleCommandInfoAlterers(array $directoryList, string $baseNamespace)

Discover command info alterers in modules.

Parameters

array $directoryList

List of directories to search

string $baseNamespace

The namespace to use at the base of each search directory. Namespace components mirror directory structure.

Return Value

array

array instantiateYamlCliCommands()

Instantiate commands from Grasmash\YamlCli that we want to expose as Drush commands.

Return Value

array

List of Symfony Command objects

array instantiateServices(array $bootstrapCommandClasses, ContainerInterface $drushContainer, ContainerInterface|null $container = null)

Instantiate objects given a lsit of classes. For each class, if it has a static create factory, use that to instantiate it, passing both the Drupal and Drush DI containers. If there is no static factory, then instantiate it via 'new $class'

Parameters

array $bootstrapCommandClasses

Classes to instantiate.

ContainerInterface $drushContainer
ContainerInterface|null $container

Return Value

array

List of instantiated service objects

protected bool supportsCompoundContainer($class, $drush_container)

Determine if the first parameter of the create method supports our container with delegate.

Parameters

$class
$drush_container

Return Value

bool

protected bool hasStaticCreateFactory(string $class)

Check to see if the provided class has a static create method.

Parameters

string $class

The name of the class to check

Return Value

bool

True if class has a static create method.

protected int|null bootStrapAttributeValue(string $class)

No description

Parameters

string $class

Return Value

int|null

protected bool requiresBootstrap(string $class)

Check whether a command class requires Drupal bootstrap.

Parameters

string $class

Return Value

bool

protected bool hasStaticCreateEarlyFactory(string $class)

Check to see if the provided class has a static createEarly method.

Parameters

string $class

The name of the class to check

Return Value

bool

True if class has a static createEarly method.

protected bool hasStaticMethod(string $class, string $methodName)

Check to see if the provided class has the specified static method.

Parameters

string $class

The name of the class to check

string $methodName

The name of the method the class should have

Return Value

bool

True if class has a static method with the specified name.

array discoverModuleGenerators(array $directoryList, string $baseNamespace)

Return generators that ship in modules.

Parameters

array $directoryList
string $baseNamespace

Return Value

array

List of generator classes

void inflect(ContainerInterface $container, mixed $object)

Inject any dependencies needed via the "*AwareInterface" pattern

Parameters

ContainerInterface $container

The DI contaner

mixed $object

The object to be inflected

Return Value

void