Skip to content

Commit 71adf22

Browse files
committed
Merge pull request #51 from MySchoolManagement/master
CacheFlushCommand was using features from PHP 5.6 but the lowest supp…
2 parents 592f9f0 + 5d208d8 commit 71adf22

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/Command/CacheFlushCommand.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626
*/
2727
class CacheFlushCommand extends ContainerAwareCommand
2828
{
29-
const VALID_TYPES = ['all', 'annotation', 'session', 'serializer', 'router', 'doctrine', 'symfony', 'validation', 'provider'];
30-
3129
/**
3230
* {@inheritdoc}
3331
*/
3432
protected function configure()
3533
{
3634
$this->setName('cache:flush');
3735
$this->setDescription('Flushes the given cache');
38-
$this->addArgument('type', InputArgument::OPTIONAL, sprintf('Which type of cache do you want to clear? Valid types are: %s', implode(', ', self::VALID_TYPES)));
36+
$this->addArgument('type', InputArgument::OPTIONAL, sprintf('Which type of cache do you want to clear? Valid types are: %s', implode(', ', $this->getValidTypes())));
3937
$this->addArgument('service', InputArgument::OPTIONAL, 'If using type "provider" you must give a service id for the cache you want to clear.');
4038
$this->setHelp(<<<'EOD'
4139
@@ -139,7 +137,8 @@ private function clearTypedCacheFromService($type, $serviceId)
139137
*/
140138
protected function verifyArguments(InputInterface $input, OutputInterface $output)
141139
{
142-
$type = $input->getArgument('type');
140+
$type = $input->getArgument('type');
141+
$validTypes = $this->getValidTypes();
143142
if ($type === null) {
144143
// ask a question and default $type='all'
145144
$helper = $this->getHelper('question');
@@ -152,12 +151,12 @@ protected function verifyArguments(InputInterface $input, OutputInterface $outpu
152151
$type = 'all';
153152
}
154153

155-
if (!in_array($type, self::VALID_TYPES)) {
154+
if (!in_array($type, $validTypes)) {
156155
$output->writeln(
157156
sprintf(
158157
'<error>Type "%s" does not exist. Valid type are: %s.</error>',
159158
$type,
160-
implode(', ', self::VALID_TYPES)
159+
implode(', ', $validTypes)
161160
)
162161
);
163162

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

204203
return $command->run(new ArrayInput($arguments), $output) === 0;
205204
}
205+
206+
/**
207+
* List of valid cache identifiers.
208+
*
209+
* @return string[]
210+
*/
211+
private function getValidTypes()
212+
{
213+
return ['all', 'annotation', 'session', 'serializer', 'router', 'doctrine', 'symfony', 'validation', 'provider'];
214+
}
206215
}

0 commit comments

Comments
 (0)