Skip to content
Merged
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
21 changes: 15 additions & 6 deletions src/Command/CacheFlushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@
*/
class CacheFlushCommand extends ContainerAwareCommand
{
const VALID_TYPES = ['all', 'annotation', 'session', 'serializer', 'router', 'doctrine', 'symfony', 'validation', 'provider'];

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('cache:flush');
$this->setDescription('Flushes the given cache');
$this->addArgument('type', InputArgument::OPTIONAL, sprintf('Which type of cache do you want to clear? Valid types are: %s', implode(', ', self::VALID_TYPES)));
$this->addArgument('type', InputArgument::OPTIONAL, sprintf('Which type of cache do you want to clear? Valid types are: %s', implode(', ', $this->getValidTypes())));
$this->addArgument('service', InputArgument::OPTIONAL, 'If using type "provider" you must give a service id for the cache you want to clear.');
$this->setHelp(<<<'EOD'

Expand Down Expand Up @@ -139,7 +137,8 @@ private function clearTypedCacheFromService($type, $serviceId)
*/
protected function verifyArguments(InputInterface $input, OutputInterface $output)
{
$type = $input->getArgument('type');
$type = $input->getArgument('type');
$validTypes = $this->getValidTypes();
if ($type === null) {
// ask a question and default $type='all'
$helper = $this->getHelper('question');
Expand All @@ -152,12 +151,12 @@ protected function verifyArguments(InputInterface $input, OutputInterface $outpu
$type = 'all';
}

if (!in_array($type, self::VALID_TYPES)) {
if (!in_array($type, $validTypes)) {
$output->writeln(
sprintf(
'<error>Type "%s" does not exist. Valid type are: %s.</error>',
$type,
implode(', ', self::VALID_TYPES)
implode(', ', $validTypes)
)
);

Expand Down Expand Up @@ -203,4 +202,14 @@ protected function clearSymfonyCache(OutputInterface $output)

return $command->run(new ArrayInput($arguments), $output) === 0;
}

/**
* List of valid cache identifiers.
*
* @return string[]
*/
private function getValidTypes()
{
return ['all', 'annotation', 'session', 'serializer', 'router', 'doctrine', 'symfony', 'validation', 'provider'];
}
}