Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ManagementLogDetailLogic
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 executeImpl
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Management;
6
7use ZipArchive;
8use PeServer\Core\Mime;
9use PeServer\Core\Binary;
10use PeServer\Core\Archiver;
11use PeServer\Core\IO\File;
12use PeServer\Core\IO\Path;
13use PeServer\Core\Text;
14use PeServer\Core\Mvc\LogicCallMode;
15use PeServer\Core\Mvc\LogicParameter;
16use PeServer\App\Models\AppConfiguration;
17use PeServer\Core\Throws\FileNotFoundException;
18use PeServer\App\Models\Domain\Page\PageLogicBase;
19
20ini_set('memory_limit', '-1');
21
22class ManagementLogDetailLogic extends PageLogicBase
23{
24    public function __construct(LogicParameter $parameter, private AppConfiguration $config)
25    {
26        parent::__construct($parameter);
27    }
28
29    protected function validateImpl(LogicCallMode $callMode): void
30    {
31        //NOP
32    }
33
34    protected function executeImpl(LogicCallMode $callMode): void
35    {
36        $logging = $this->config->setting->logging;
37        /** @var string */
38        $dirPath = $logging->loggers['file']->configuration['directory'];
39
40        $fileName = Text::trim($this->getRequest('log_name'), '/\\.');
41        $filePath = Path::combine($dirPath, $fileName);
42        if (!File::exists($filePath)) {
43            throw new FileNotFoundException();
44        }
45
46        $binary = File::readContent($filePath);
47
48        $archiveSize = $logging->archiveSize;
49        $fileSize = File::getFileSize($filePath);
50
51        if ($archiveSize <= $fileSize || $callMode === LogicCallMode::Submit) {
52            $this->result['download'] = true;
53
54            $compressed = Archiver::compressGzip($binary, 9);
55
56            $this->setDownloadContent(Mime::GZ, $fileName . '.gz', $compressed);
57        } else {
58            $this->setValue('log_name', $fileName);
59            $this->setValue('log_file', $filePath);
60            $this->setValue('log_value', $binary->raw);
61        }
62    }
63}