3 namespace Drush\Drupal;
5 use Drush\Log\LogLevel;
6 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
7 use Drupal\Core\DependencyInjection\ContainerBuilder;
9 class DrushServiceModifier implements ServiceModifierInterface
11 // Holds list of command classes implementing Symfony\Console\Component\Command
12 const DRUSH_CONSOLE_SERVICES = 'drush.console.services';
13 // Holds list of command classes implemented with annotated commands
14 const DRUSH_COMMAND_SERVICES = 'drush.command.services';
15 // Holds list of command info alterer classes.
16 const DRUSH_COMMAND_INFO_ALTERER_SERVICES = 'drush.command_info_alterer.services';
17 // Holds list of classes implementing Drupal Code Generator classes
18 const DRUSH_GENERATOR_SERVICES = 'drush.generator.services';
23 public function alter(ContainerBuilder $container)
25 drush_log(dt("Service modifier alter."), LogLevel::DEBUG_NOTIFY);
26 // http://symfony.com/doc/2.7/components/dependency_injection/tags.html#register-the-pass-with-the-container
27 $container->register(self::DRUSH_CONSOLE_SERVICES, 'Drush\Command\ServiceCommandlist');
28 $container->addCompilerPass(new FindCommandsCompilerPass(self::DRUSH_CONSOLE_SERVICES, 'console.command'));
29 $container->register(self::DRUSH_COMMAND_SERVICES, 'Drush\Command\ServiceCommandlist');
30 $container->addCompilerPass(new FindCommandsCompilerPass(self::DRUSH_COMMAND_SERVICES, 'drush.command'));
31 $container->register(self::DRUSH_COMMAND_INFO_ALTERER_SERVICES, 'Drush\Command\ServiceCommandlist');
32 $container->addCompilerPass(new FindCommandsCompilerPass(self::DRUSH_COMMAND_INFO_ALTERER_SERVICES, 'drush.command_info_alterer'));
33 $container->register(self::DRUSH_GENERATOR_SERVICES, 'Drush\Command\ServiceCommandlist');
34 $container->addCompilerPass(new FindCommandsCompilerPass(self::DRUSH_GENERATOR_SERVICES, 'drush.generator'));
38 * Checks existing service definitions for the presence of modification.
40 * @param $container_definition
41 * Cached container definition
44 public function check($container_definition)
47 isset($container_definition['services'][self::DRUSH_CONSOLE_SERVICES]) &&
48 isset($container_definition['services'][self::DRUSH_COMMAND_SERVICES]) &&
49 isset($container_definition['services'][self::DRUSH_COMMAND_INFO_ALTERER_SERVICES]) &&
50 isset($container_definition['services'][self::DRUSH_GENERATOR_SERVICES]);