1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace pjpawel\LightApi\Command\Internal; |
4
|
|
|
|
5
|
|
|
use pjpawel\LightApi\Command\CommandsLoader; |
6
|
|
|
use pjpawel\LightApi\Command\Input\InputInterface; |
7
|
|
|
use pjpawel\LightApi\Command\Output\OutputInterface; |
8
|
|
|
use pjpawel\LightApi\Component\FilesManager; |
9
|
|
|
use pjpawel\LightApi\Component\Serializer; |
10
|
|
|
use pjpawel\LightApi\Container\ContainerLoader; |
11
|
|
|
use pjpawel\LightApi\Kernel; |
12
|
|
|
use pjpawel\LightApi\Route\Router; |
13
|
|
|
use ReflectionClass; |
14
|
|
|
|
15
|
|
|
class WarmUpCacheCommand extends KernelAwareCommand |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
private FilesManager $filesManager; |
19
|
|
|
|
20
|
|
|
public function __construct() |
21
|
|
|
{ |
22
|
|
|
$this->filesManager = new FilesManager(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritDoc |
27
|
|
|
*/ |
28
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int |
29
|
|
|
{ |
30
|
|
|
$reflectionClass = new ReflectionClass(Kernel::class); |
31
|
|
|
/** @var Serializer $serializer */ |
32
|
|
|
$serializer = $reflectionClass->getProperty('serializer')->getValue($this->kernel); |
33
|
|
|
$serializerClass = new ReflectionClass($serializer); |
34
|
|
|
$serializerDir = $serializerClass->getProperty('serializedDir')->getValue($serializer); |
35
|
|
|
if (is_dir($serializerDir)) { |
36
|
|
|
$this->filesManager->removeDirRecursive($serializerDir); |
37
|
|
|
} |
38
|
|
|
$serializer->makeSerialization([ |
39
|
|
|
ContainerLoader::class => $reflectionClass->getProperty('containerLoader')->getValue($this->kernel), |
40
|
|
|
Router::class => $reflectionClass->getProperty('router')->getValue($this->kernel), |
41
|
|
|
CommandsLoader::class => $reflectionClass->getProperty('commandLoader')->getValue($this->kernel) |
42
|
|
|
]); |
43
|
|
|
return self::SUCCESS; |
44
|
|
|
} |
45
|
|
|
} |