|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * Contains \Drupal\Console\Command\Cache\TagInvalidateCommand. |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Drupal\Console\Command\Cache; |
| 9 | + |
| 10 | +use Drupal\Console\Core\Command\Shared\CommandTrait; |
| 11 | +use Drupal\Console\Core\Style\DrupalStyle; |
| 12 | +use Drupal\Core\Cache\CacheTagsInvalidatorInterface; |
| 13 | +use Symfony\Component\Console\Command\Command; |
| 14 | +use Symfony\Component\Console\Input\InputArgument; |
| 15 | +use Symfony\Component\Console\Input\InputInterface; |
| 16 | +use Symfony\Component\Console\Output\OutputInterface; |
| 17 | + |
| 18 | +class TagInvalidateCommand extends Command |
| 19 | +{ |
| 20 | + use CommandTrait; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var CacheTagsInvalidatorInterface |
| 24 | + */ |
| 25 | + protected $invalidator; |
| 26 | + |
| 27 | + /** |
| 28 | + * TagInvalidateCommand constructor. |
| 29 | + * |
| 30 | + * @param CacheTagsInvalidatorInterface $invalidator |
| 31 | + */ |
| 32 | + public function __construct(CacheTagsInvalidatorInterface $invalidator) |
| 33 | + { |
| 34 | + parent::__construct(); |
| 35 | + $this->invalidator = $invalidator; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * {@inheritdoc} |
| 40 | + */ |
| 41 | + protected function configure() |
| 42 | + { |
| 43 | + $this |
| 44 | + ->setName('cache:tag:invalidate') |
| 45 | + ->setDescription($this->trans('commands.cache.tag.invalidate.description')) |
| 46 | + ->addArgument( |
| 47 | + 'tag', |
| 48 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
| 49 | + $this->trans('commands.cache.tag.invalidate.options.tag') |
| 50 | + ) |
| 51 | + ->setAliases(['cti']); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * {@inheritdoc} |
| 56 | + */ |
| 57 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 58 | + { |
| 59 | + $io = new DrupalStyle($input, $output); |
| 60 | + $tags = $input->getArgument('tag'); |
| 61 | + |
| 62 | + $io->comment( |
| 63 | + sprintf( |
| 64 | + $this->trans('commands.cache.tag.invalidate.messages.start'), |
| 65 | + implode(', ', $tags) |
| 66 | + ) |
| 67 | + ); |
| 68 | + |
| 69 | + $this->invalidator->invalidateTags($tags); |
| 70 | + $io->success($this->trans('commands.cache.tag.invalidate.messages.completed')); |
| 71 | + } |
| 72 | +} |
0 commit comments