get('application'); } /** * Return the Robo runner. * * @return \Robo\Runner */ public static function runner() { if (!isset(static::$runner)) { static::$runner = new \Robo\Runner(); } return static::$runner; } /** * 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. * * @param string $id * The ID of the service to retrieve. * * @return mixed * The specified service. */ public static function service($id) { return static::getContainer()->get($id); } /** * Indicates if a service is defined in the container. * * @param string $id * The ID of the service to check. * * @return bool * TRUE if the specified service exists, FALSE otherwise. */ public static function hasService($id) { // Check hasContainer() first in order to always return a Boolean. return static::hasContainer() && static::getContainer()->has($id); } /** * Return command factory * * @return \Consolidation\AnnotatedCommand\AnnotatedCommandFactory */ public static function commandFactory() { return static::service('commandFactory'); } /** * Return the Drush logger object. * * @return LoggerInterface */ public static function logger() { return static::service('logger'); } /** * Return the configuration object * * @return \Drush\Config\DrushConfig */ public static function config() { return static::service('config'); } /** * @return SiteAliasManager */ public static function aliasManager() { return static::service('site.alias.manager'); } /** * Return the input object * * @return InputInterface */ public static function input() { return static::service('input'); } /** * Return the output object * * @return OutputInterface */ public static function output() { return static::service('output'); } /** * Return 'true' if we are in simulated mode */ public static function simulate() { return \Drush\Drush::config()->get(\Robo\Config\Config::SIMULATE); } /** * Return 'true' if we are in backend mode */ public static function backend() { return \Drush\Drush::config()->get(PreflightArgs::BACKEND); } /** * Return 'true' if we are in affirmative mode */ public static function affirmative() { if (!static::hasService('input')) { throw new \Exception('No input service available.'); } return Drush::input()->getOption('yes') || (Drush::backend() && !Drush::negative()); } /** * Return 'true' if we are in negative mode */ public static function negative() { if (!static::hasService('input')) { throw new \Exception('No input service available.'); } return Drush::input()->getOption('no'); } /** * Return 'true' if we are in verbose mode */ public static function verbose() { if (!static::hasService('output')) { return false; } return \Drush\Drush::output()->isVerbose(); } /** * Return 'true' if we are in debug mode */ public static function debug() { if (!static::hasService('output')) { return false; } return \Drush\Drush::output()->isDebug(); } /** * Return the Bootstrap Manager. * * @return \Drush\Boot\BootstrapManager */ public static function bootstrapManager() { return static::service('bootstrap.manager'); } /** * Return the Bootstrap object. * * @return \Drush\Boot\Boot */ public static function bootstrap() { return static::bootstrapManager()->bootstrap(); } public static function redispatchOptions($input = null) { $input = $input ?: static::input(); // $input->getOptions() returns an associative array of option => value $options = $input->getOptions(); // The 'runtime.options' config contains a list of option names on th cli $optionNamesFromCommandline = static::config()->get('runtime.options'); // Remove anything in $options that was not on the cli $options = array_intersect_key($options, array_flip($optionNamesFromCommandline)); // Add in the 'runtime.context' items, which includes --include, --alias-path et. al. return $options + array_filter(static::config()->get(PreflightArgs::DRUSH_RUNTIME_CONTEXT_NAMESPACE)); } /** * Read the drush info file. */ private static function drushReadDrushInfo() { $drush_info_file = dirname(__FILE__) . '/../drush.info'; return parse_ini_file($drush_info_file); } }