1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
/**
* @api
* @since 100.0.2
*/
abstract class AbstractCacheManageCommand extends AbstractCacheCommand
{
/**
* Input argument types
*/
const INPUT_KEY_TYPES = 'types';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->addArgument(
self::INPUT_KEY_TYPES,
InputArgument::IS_ARRAY,
'Space-separated list of cache types or omit to apply to all cache types.'
);
parent::configure();
}
/**
* Get requested cache types
*
* @param InputInterface $input
* @return array
*/
protected function getRequestedTypes(InputInterface $input)
{
$requestedTypes = [];
if ($input->getArgument(self::INPUT_KEY_TYPES)) {
$requestedTypes = $input->getArgument(self::INPUT_KEY_TYPES);
$requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
}
if (empty($requestedTypes)) {
return $this->cacheManager->getAvailableTypes();
} else {
$availableTypes = $this->cacheManager->getAvailableTypes();
$unsupportedTypes = array_diff($requestedTypes, $availableTypes);
if ($unsupportedTypes) {
throw new \InvalidArgumentException(
"The following requested cache types are not supported: '" . join("', '", $unsupportedTypes)
. "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes)
);
}
return array_values(array_intersect($availableTypes, $requestedTypes));
}
}
}