Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
HomeWildcardLogic | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
5.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateImpl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
executeImpl | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\Home; |
6 | |
7 | use PeServer\Core\IO\IOUtility; |
8 | use PeServer\Core\IO\Path; |
9 | use PeServer\Core\Mvc\LogicCallMode; |
10 | use PeServer\Core\Mvc\LogicParameter; |
11 | use PeServer\App\Models\AppConfiguration; |
12 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
13 | use PeServer\Core\Environment; |
14 | use PeServer\Core\Http\HttpStatus; |
15 | use PeServer\Core\IO\File; |
16 | use PeServer\Core\Mime; |
17 | use PeServer\Core\ProgramContext; |
18 | use PeServer\Core\Text; |
19 | use PeServer\Core\Throws\HttpStatusException; |
20 | |
21 | class HomeWildcardLogic extends PageLogicBase |
22 | { |
23 | public function __construct(LogicParameter $parameter, private ProgramContext $programContext) |
24 | { |
25 | parent::__construct($parameter); |
26 | } |
27 | |
28 | protected function validateImpl(LogicCallMode $callMode): void |
29 | { |
30 | //NOP |
31 | } |
32 | |
33 | protected function executeImpl(LogicCallMode $callMode): void |
34 | { |
35 | $unsafeRequestPath = $this->getRequest('path'); |
36 | |
37 | $requestFileName = Path::getFileName($unsafeRequestPath); |
38 | $assetsDirPath = Path::combine($this->programContext->rootDirectory, 'assets'); |
39 | $targetPath = Path::combine($assetsDirPath, $requestFileName); |
40 | |
41 | if (Text::startsWith($targetPath, $assetsDirPath, true)) { |
42 | if (File::exists($targetPath)) { |
43 | $this->setFileContent(null, $targetPath); |
44 | return; |
45 | } |
46 | } |
47 | |
48 | |
49 | throw new HttpStatusException(HttpStatus::NotFound, $unsafeRequestPath); |
50 | } |
51 | } |