Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cache:context:debug] Create command and move cache:rebuild command (#…
…2489) * Create cache:context:list command and move cache:rebuild command into new namespace * change command to cache:context:debug * rename classes to fit convention * should be the last fix * remove use alias * fix comments * fix comments
- Loading branch information
1 parent
6d23fc8
commit 6cbb4a9
Showing
5 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
description: 'Displays current cache context for the application.' | ||
messages: | ||
code: 'Context ID' | ||
label: 'Label' | ||
class: 'Class path' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Console\Command\Cache\ContextDebugCommand. | ||
*/ | ||
|
||
namespace Drupal\Console\Command\Cache; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait; | ||
use Drupal\Console\Style\DrupalStyle; | ||
|
||
/** | ||
* Class ContextDebugCommand. | ||
* | ||
* @package Drupal\Console\Command\Cache | ||
*/ | ||
class ContextDebugCommand extends Command | ||
{ | ||
use ContainerAwareCommandTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters