Drush
class Drush (View source)
Static Service Container wrapper.
This code is analogous to the \Drupal class.
We would like to move Drush towards the model of using constructor injection rather than globals. This class serves as a unified global accessor to arbitrary services for use by legacy Drush code.
Advice from Drupal's 'Drupal' class:
This class exists only to support legacy code that cannot be dependency injected. If your code needs it, consider refactoring it to be object oriented, if possible. When this is not possible, and your code is more than a few non-reusable lines, it is recommended to instantiate an object implementing the actual logic.
Constants
protected TIMEOUT |
Number of seconds before timeout for subprocesses. Can be customized via setTimeout() method. |
Properties
static protected string|false | $version | The version of Drush from Composer Runtime, or FALSE if not populated yet. |
|
static protected string|false | $majorVersion | ||
static protected string|false | $minorVersion | ||
static protected Runner | $runner | The Robo Runner -- manages and constructs all commandfile classes |
Methods
No description
Return the current Drush version.
Convert internal Composer dev version to ".x"
No description
No description
Sets a new global container.
Unsets the global container.
Returns the currently active global container.
Returns TRUE if the container has been initialized, FALSE otherwise.
Get the current Symfony Console Application.
Return the Robo runner.
Retrieves a service from the container.
Indicates if a service is defined in the container.
Return command factory
Return the Drush logger object.
Return the configuration object
No description
No description
Return the input object
Return the output object
Run a Drush command on a site alias (or @self).
Run a bash fragment on a site alias.
Run a bash fragment locally.
Create a Process instance from a commandline string.
Return 'true' if we are in simulated mode
Return 'true' if we are in affirmative mode
Return 'true' if we are in negative mode
Return 'true' if we are in verbose mode
Return 'true' if we are in debug mode
Return the Bootstrap Manager.
Return the Bootstrap object.
No description
Details
static int
getTimeout()
No description
static string|false
getVersion()
Return the current Drush version.
n.b. Called before the DI container is initialized. Do not log, etc. here.
static string
sanitizeVersionString($version)
Convert internal Composer dev version to ".x"
static string
getMajorVersion()
No description
static string
getMinorVersion()
No description
static void
setContainer($container)
Sets a new global container.
static void
unsetContainer()
Unsets the global container.
static ContainerInterface
getContainer()
Returns the currently active global container.
static bool
hasContainer()
Returns TRUE if the container has been initialized, FALSE otherwise.
static Application
getApplication()
Get the current Symfony Console Application.
static Runner
runner()
Return the Robo runner.
static
service(string $id)
Retrieves a service from the container.
Use this method if the desired service is not one of those with a dedicated accessor method below. If it is listed below, those methods are preferred as they can return useful type hints.
static bool
hasService(string $id)
Indicates if a service is defined in the container.
static AnnotatedCommandFactory
commandFactory()
Return command factory
static LoggerInterface
logger()
internal | Commands should use $this->logger() instead. |
Return the Drush logger object.
static DrushConfig
config()
internal | Commands should use $this->config() instead. |
Return the configuration object
static SiteAliasManager
aliasManager()
internal | Commands should use $this->siteAliasManager() instead. |
No description
static ProcessManager
processManager()
internal | Commands should use $this->processManager() instead. |
No description
static InputInterface
input()
Return the input object
static OutputInterface
output()
Return the output object
static SiteProcess
drush(SiteAliasInterface $siteAlias, string $command, array $args = [], array $options = [], array $options_double_dash = [])
Run a Drush command on a site alias (or @self).
Tip: Use injected processManager() instead of this method. See below.
A class should use ProcessManagerAwareInterface / ProcessManagerAwareTrait in order to have the Process Manager injected by Drush's DI container. For example:
use Consolidation\SiteProcess\ProcessManagerAwareTrait;
use Consolidation\SiteProcess\ProcessManagerAwareInterface;
abstract class DrushCommands implements ProcessManagerAwareInterface ...
{
use ProcessManagerAwareTrait;
}
Since DrushCommands already uses ProcessManagerAwareTrait, all Drush commands may use the process manager to call other Drush commands. Other classes will need to ensure that the process manager is injected as shown above.
Note, however, that an alias record is required to use the drush
method.
Dependency inject the site alias manager to get an alias record.
Clients that are using Drush::drush(), and need a reference to the alias manager may use Drush::aliasManager().
static ProcessBase
siteProcess(SiteAliasInterface $siteAlias, array $args = [], array $options = [], array $options_double_dash = [])
Run a bash fragment on a site alias.
Use \Drush\Drush::drush() instead of this method when calling Drush.
Tip: Commands can consider using $this->processManager() instead of this method.
static ProcessBase
process(string|array $commandline, string|null $cwd = null, array|null $env = null, mixed $input = null, int|float|null $timeout = 60)
Run a bash fragment locally.
The timeout parameter on this method doesn't work. It exists for compatibility with parent. Call this method to get a Process and then call setters as needed.
Tip: Commandfiles should use processmanager() instead of this method.
static ProcessBase
shell(string $command, string|null $cwd = null, array|null $env = null, mixed $input = null, int|float|null $timeout = 60)
Create a Process instance from a commandline string.
Tip: Consider using injected process manager instead of this method.
static
simulate()
internal | Commands should use $this->getConfig()->simulate(). |
Return 'true' if we are in simulated mode
static
affirmative()
Return 'true' if we are in affirmative mode
static
negative()
Return 'true' if we are in negative mode
static bool
verbose()
Return 'true' if we are in verbose mode
static bool
debug()
Return 'true' if we are in debug mode
static BootstrapManager
bootstrapManager()
Return the Bootstrap Manager.
static DrupalBoot8
bootstrap()
Return the Bootstrap object.
static array
redispatchOptions($input = null)
No description