Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

/**
* @api
* @since 100.0.2
*/
abstract class AbstractCacheManageCommand extends AbstractCacheCommand
{
/**
* Input argument types
*/
const INPUT_KEY_TYPES = 'types';
public const INPUT_KEY_TYPES = 'types';

public const EXCLUDE_KEY_TYPES = 'exclude';

/**
* {@inheritdoc}
* @inheritdoc
*/
protected function configure()
{
Expand All @@ -30,6 +29,12 @@ protected function configure()
InputArgument::IS_ARRAY,
'Space-separated list of cache types or omit to apply to all cache types.'
);
$this->addOption(
self::EXCLUDE_KEY_TYPES,
'e',
InputOption::VALUE_OPTIONAL,
'Comma separated list of cache types to omit'
);
parent::configure();
}

Expand All @@ -46,8 +51,16 @@ protected function getRequestedTypes(InputInterface $input)
$requestedTypes = $input->getArgument(self::INPUT_KEY_TYPES);
$requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
}
$excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES);
if (empty($requestedTypes)) {
return $this->cacheManager->getAvailableTypes();
$cacheTypes = $this->cacheManager->getAvailableTypes();
if (!empty($excludeTypes)) {
foreach (explode(',', $excludeTypes) as $item) {
unset($cacheTypes[array_search($item, $cacheTypes)]);
}
$cacheTypes = array_values($cacheTypes);
}
return $cacheTypes;
} else {
$availableTypes = $this->cacheManager->getAvailableTypes();
$unsupportedTypes = array_diff($requestedTypes, $availableTypes);
Expand All @@ -57,6 +70,12 @@ protected function getRequestedTypes(InputInterface $input)
. "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes)
);
}
if (!empty($excludeTypes)) {
foreach (explode(',', $excludeTypes) as $item) {
unset($availableTypes[array_search($item, $availableTypes)]);
}
$availableTypes = array_values($availableTypes);
}
return array_values(array_intersect($availableTypes, $requestedTypes));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->performAction($types);
$output->writeln($this->getDisplayMessage());
$output->writeln(join(PHP_EOL, $types));
$excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES);
if (!empty($excludeTypes)) {
$output->writeln('Excluded Cache Type');
foreach (explode(',', $excludeTypes) as $type) {
$output->writeln($type);
}
}

return Cli::RETURN_SUCCESS;
}
Expand Down