Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ManagementLogListLogic | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateImpl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
executeImpl | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\Management; |
6 | |
7 | use PeServer\Core\IO\Directory; |
8 | use PeServer\Core\IO\File; |
9 | use PeServer\Core\IO\Path; |
10 | use PeServer\Core\SizeConverter; |
11 | use PeServer\Core\Mvc\LogicCallMode; |
12 | use PeServer\Core\Mvc\LogicParameter; |
13 | use PeServer\App\Models\AppConfiguration; |
14 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
15 | use PeServer\Core\Collection\Arr; |
16 | use PeServer\Core\Collection\Collections; |
17 | |
18 | class ManagementLogListLogic extends PageLogicBase |
19 | { |
20 | public function __construct(LogicParameter $parameter, private AppConfiguration $config) |
21 | { |
22 | parent::__construct($parameter); |
23 | } |
24 | |
25 | protected function validateImpl(LogicCallMode $callMode): void |
26 | { |
27 | //NOP |
28 | } |
29 | |
30 | protected function executeImpl(LogicCallMode $callMode): void |
31 | { |
32 | $logging = $this->config->setting->logging; |
33 | $dirPath = $logging->loggers['file']->configuration['directory']; |
34 | $targetExt = Path::getFileExtension($logging->loggers['file']->configuration['name']); |
35 | $files = Directory::getFiles($dirPath, false); |
36 | |
37 | $logFiles = array_filter($files, function ($i) use ($targetExt) { |
38 | return Path::getFileExtension($i) === $targetExt; |
39 | }); |
40 | $logFiles = Collections::from(Arr::sortNaturalByValue($logFiles, true)) |
41 | ->select(function ($i) { |
42 | $sizeConverter = new SizeConverter(); |
43 | $size = File::getFileSize($i); |
44 | return [ |
45 | 'directory' => Path::getDirectoryPath($i), |
46 | 'name' => Path::getFileName($i), |
47 | 'size' => $size, |
48 | 'human_size' => $sizeConverter->convertHumanReadableByte($size, '{f_size} {unit}'), |
49 | ]; |
50 | }) |
51 | ->reverse() |
52 | ->toList(); |
53 | |
54 | $this->setValue('directory', $dirPath); |
55 | $this->setValue('log_files', $logFiles); |
56 | } |
57 | } |