88
99use Symfony \Component \Console \Input \InputArgument ;
1010use Symfony \Component \Console \Input \InputInterface ;
11+ use Symfony \Component \Console \Input \InputOption ;
1112
1213/**
1314 * @api
@@ -20,6 +21,8 @@ abstract class AbstractCacheManageCommand extends AbstractCacheCommand
2021 */
2122 const INPUT_KEY_TYPES = 'types ' ;
2223
24+ const EXCLUDE_KEY_TYPES = 'exclude ' ;
25+
2326 /**
2427 * {@inheritdoc}
2528 */
@@ -30,6 +33,12 @@ protected function configure()
3033 InputArgument::IS_ARRAY ,
3134 'Space-separated list of cache types or omit to apply to all cache types. '
3235 );
36+ $ this ->addOption (
37+ self ::EXCLUDE_KEY_TYPES ,
38+ 'e ' ,
39+ InputOption::VALUE_OPTIONAL ,
40+ 'Comma separated list of cache types to omit '
41+ );
3342 parent ::configure ();
3443 }
3544
@@ -46,8 +55,16 @@ protected function getRequestedTypes(InputInterface $input)
4655 $ requestedTypes = $ input ->getArgument (self ::INPUT_KEY_TYPES );
4756 $ requestedTypes = array_filter (array_map ('trim ' , $ requestedTypes ), 'strlen ' );
4857 }
58+ $ excludeTypes = $ input ->getOption (self ::EXCLUDE_KEY_TYPES );
4959 if (empty ($ requestedTypes )) {
50- return $ this ->cacheManager ->getAvailableTypes ();
60+ $ cacheTypes = $ this ->cacheManager ->getAvailableTypes ();
61+ if (!empty ($ excludeTypes )) {
62+ foreach (explode (', ' , $ excludeTypes ) as $ item ) {
63+ unset($ cacheTypes [array_search ($ item , $ cacheTypes )]);
64+ }
65+ $ cacheTypes = array_values ($ cacheTypes );
66+ }
67+ return $ cacheTypes ;
5168 } else {
5269 $ availableTypes = $ this ->cacheManager ->getAvailableTypes ();
5370 $ unsupportedTypes = array_diff ($ requestedTypes , $ availableTypes );
@@ -57,6 +74,12 @@ protected function getRequestedTypes(InputInterface $input)
5774 . "'. " . PHP_EOL . 'Supported types: ' . join (", " , $ availableTypes )
5875 );
5976 }
77+ if (!empty ($ excludeTypes )) {
78+ foreach (explode (', ' , $ excludeTypes ) as $ item ) {
79+ unset($ availableTypes [array_search ($ item , $ availableTypes )]);
80+ }
81+ $ availableTypes = array_values ($ availableTypes );
82+ }
6083 return array_values (array_intersect ($ availableTypes , $ requestedTypes ));
6184 }
6285 }
0 commit comments