diff --git a/config/services/cache.yml b/config/services/cache.yml new file mode 100644 index 000000000..8447a2016 --- /dev/null +++ b/config/services/cache.yml @@ -0,0 +1,9 @@ +services: + cache_context_debug: + class: Drupal\Console\Command\Cache\ContextDebugCommand + tags: + - { name: console.command } + cache_rebuild: + class: Drupal\Console\Command\Cache\RebuildCommand + tags: + - { name: console.command } diff --git a/config/services/misc.yml b/config/services/misc.yml index ffb85ffc3..0c574261d 100644 --- a/config/services/misc.yml +++ b/config/services/misc.yml @@ -3,10 +3,6 @@ services: class: Drupal\Console\Command\AboutCommand tags: - { name: console.command } - cache_rebuild: - class: Drupal\Console\Command\CacheRebuildCommand - tags: - - { name: console.command } container_debug: class: Drupal\Console\Command\ContainerDebugCommand tags: diff --git a/config/translations/en/cache.context.debug.yml b/config/translations/en/cache.context.debug.yml new file mode 100644 index 000000000..c334f54d8 --- /dev/null +++ b/config/translations/en/cache.context.debug.yml @@ -0,0 +1,5 @@ +description: 'Displays current cache context for the application.' +messages: + code: 'Context ID' + label: 'Label' + class: 'Class path' diff --git a/src/Command/Cache/ContextDebugCommand.php b/src/Command/Cache/ContextDebugCommand.php new file mode 100644 index 000000000..835490328 --- /dev/null +++ b/src/Command/Cache/ContextDebugCommand.php @@ -0,0 +1,63 @@ +setName('cache:context:debug') + ->setDescription($this->trans('commands.cache.context.debug.description')); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $contextManager = \Drupal::service('cache_contexts_manager'); + + $tableHeader = [ + $this->trans('commands.cache.context.debug.messages.code'), + $this->trans('commands.cache.context.debug.messages.label'), + $this->trans('commands.cache.context.debug.messages.class'), + ]; + + $tableRows = []; + + foreach ($contextManager->getAll() as $code) { + $context = \Drupal::service('cache_context.'.$code); + + $tableRows[] = [ + \Drupal\Component\Utility\SafeMarkup::checkPlain($code), + $context->getLabel()->render(), + get_class($context), + ]; + } + + $io->table($tableHeader, $tableRows, 'compact'); + } +} diff --git a/src/Command/CacheRebuildCommand.php b/src/Command/Cache/RebuildCommand.php similarity index 91% rename from src/Command/CacheRebuildCommand.php rename to src/Command/Cache/RebuildCommand.php index c556190f8..c075df0d2 100644 --- a/src/Command/CacheRebuildCommand.php +++ b/src/Command/Cache/RebuildCommand.php @@ -2,23 +2,23 @@ /** * @file - * Contains \Drupal\Console\Command\CacheRebuildCommand. + * Contains \Drupal\Console\Command\Cache\RebuildCommand. */ -namespace Drupal\Console\Command; +namespace Drupal\Console\Command\Cache; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command as BaseCommand; +use Symfony\Component\Console\Command\Command; use Drupal\Console\Command\Shared\ContainerAwareCommandTrait; use Drupal\Console\Style\DrupalStyle; /** - * Class CacheRebuildCommand - * @package Drupal\Console\Command + * Class RebuildCommand + * @package Drupal\Console\Command\Cache */ -class CacheRebuildCommand extends BaseCommand +class RebuildCommand extends Command { use ContainerAwareCommandTrait;