1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Console\Commands\AbterPhp; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Console\Commands\Assets\FlushCache as AssetsFlushCacheCommand; |
8
|
|
|
use AbterPhp\Framework\Console\Commands\Authorization\FlushCache as AuthorizationFlushCacheCommand; |
9
|
|
|
use AbterPhp\Framework\Console\Commands\Template\FlushCache as TemplateFlushCacheCommand; |
10
|
|
|
use Opulence\Console\Commands\Command; |
11
|
|
|
use Opulence\Console\Responses\IResponse; |
12
|
|
|
|
13
|
|
|
class FlushCache extends Command |
14
|
|
|
{ |
15
|
|
|
protected const NAME = 'abterphp:flushcache'; |
16
|
|
|
|
17
|
|
|
protected const DESCRIPTION = 'Flushes all registered cache types'; |
18
|
|
|
|
19
|
|
|
protected const OPULENCE_FRAMEWORK_FLUSHCACHE = 'framework:flushcache'; |
20
|
|
|
|
21
|
|
|
/** @var string[] */ |
22
|
|
|
protected array $subCommands = [ |
23
|
|
|
/** @see AssetsFlushCacheCommand::doExecute() */ |
24
|
|
|
AssetsFlushCacheCommand::NAME, |
25
|
|
|
/** @see TemplateFlushCacheCommand::doExecute() */ |
26
|
|
|
TemplateFlushCacheCommand::NAME, |
27
|
|
|
/** @see AuthorizationFlushCacheCommand::doExecute() */ |
28
|
|
|
AuthorizationFlushCacheCommand::NAME, |
29
|
|
|
/** @see \Opulence\Framework\Console\Commands\FlushFrameworkCacheCommand::doExecute() */ |
30
|
|
|
self::OPULENCE_FRAMEWORK_FLUSHCACHE, |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
protected function define(): void |
37
|
|
|
{ |
38
|
|
|
$this->setName(static::NAME) |
39
|
|
|
->setDescription(static::DESCRIPTION); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $subCommand |
44
|
|
|
*/ |
45
|
|
|
public function addSubCommand(string $subCommand): void |
46
|
|
|
{ |
47
|
|
|
$this->subCommands[] = $subCommand; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
|
|
protected function doExecute(IResponse $response): void |
54
|
|
|
{ |
55
|
|
|
foreach ($this->subCommands as $subCommand) { |
56
|
|
|
try { |
57
|
|
|
$this->commandCollection->call($subCommand, $response); |
58
|
|
|
} catch (\Exception $e) { |
59
|
|
|
$response->writeln(sprintf('<error>%s@execute failed</error>', $subCommand)); |
60
|
|
|
$response->writeln(sprintf('<fatal>%s</fatal>', $e->getMessage())); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|