Skip to content

Commit

Permalink
[cache:context:debug] Create command and move cache:rebuild command (#…
Browse files Browse the repository at this point in the history
…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
smalot authored and enzolutions committed Jul 3, 2016
1 parent 6d23fc8 commit 6cbb4a9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 10 deletions.
9 changes: 9 additions & 0 deletions 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 }
4 changes: 0 additions & 4 deletions config/services/misc.yml
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions 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'
63 changes: 63 additions & 0 deletions src/Command/Cache/ContextDebugCommand.php
@@ -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');
}
}
Expand Up @@ -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;

Expand Down

0 comments on commit 6cbb4a9

Please sign in to comment.