Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
HomeWildcardLogic
90.91% covered (success)
90.91%
10 / 11
66.67% covered (warning)
66.67%
2 / 3
5.02
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validateImpl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 executeImpl
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
3.01
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Home;
6
7use PeServer\Core\IO\IOUtility;
8use PeServer\Core\IO\Path;
9use PeServer\Core\Mvc\LogicCallMode;
10use PeServer\Core\Mvc\LogicParameter;
11use PeServer\App\Models\AppConfiguration;
12use PeServer\App\Models\Domain\Page\PageLogicBase;
13use PeServer\Core\Environment;
14use PeServer\Core\Http\HttpStatus;
15use PeServer\Core\IO\File;
16use PeServer\Core\Mime;
17use PeServer\Core\ProgramContext;
18use PeServer\Core\Text;
19use PeServer\Core\Throws\HttpStatusException;
20
21class 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}