|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author SignpostMarv |
|
4
|
|
|
*/ |
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace SignpostMarv\DaftFramework; |
|
8
|
|
|
|
|
9
|
|
|
use InvalidArgumentException; |
|
10
|
|
|
use SignpostMarv\DaftFramework\Framework; |
|
11
|
|
|
use SignpostMarv\DaftRouter\DaftSource; |
|
12
|
|
|
use SignpostMarv\DaftRouter\Router\Compiler; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class HttpHandler extends Framework |
|
18
|
|
|
{ |
|
19
|
|
|
const ERROR_SOURCE_CONFIG = DaftSource::class . ' config does not specify "%s" correctly.'; |
|
20
|
|
|
|
|
21
|
|
|
const ERROR_ROUTER_CACHE_FILE_PATH = |
|
22
|
|
|
DaftSource::class . |
|
23
|
|
|
' config property cacheFile does not exist under the framework base path.'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $routerCacheFile; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array<int, string> |
|
32
|
|
|
*/ |
|
33
|
|
|
private $routerSources; |
|
34
|
|
|
|
|
35
|
16 |
|
public function __construct(string $baseUrl, string $basePath, array $config = []) |
|
36
|
|
|
{ |
|
37
|
16 |
|
parent::__construct($baseUrl, $basePath, $config); |
|
38
|
|
|
|
|
39
|
8 |
|
$this->routerCacheFile = $config[DaftSource::class]['cacheFile']; |
|
40
|
|
|
|
|
41
|
8 |
|
$this->routerSources = array_values(array_filter( |
|
42
|
8 |
|
$config[DaftSource::class]['sources'], |
|
43
|
8 |
|
'is_string' |
|
44
|
|
|
)); |
|
45
|
8 |
|
} |
|
46
|
|
|
|
|
47
|
8 |
|
public function handle(Request $request) : Response |
|
48
|
|
|
{ |
|
49
|
8 |
|
self::PairWithRequest($this, $request); |
|
50
|
|
|
|
|
51
|
8 |
|
$dispatcher = Compiler::ObtainDispatcher( |
|
52
|
|
|
[ |
|
53
|
8 |
|
'cacheFile' => $this->routerCacheFile, |
|
54
|
|
|
], |
|
55
|
8 |
|
...$this->routerSources |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
8 |
|
return $dispatcher->handle($request, parse_url($this->ObtainBaseUrl(), PHP_URL_PATH)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
16 |
|
protected function ValidateConfig(array $config) : array |
|
62
|
|
|
{ |
|
63
|
|
|
if ( |
|
64
|
|
|
! isset( |
|
65
|
16 |
|
$config[DaftSource::class], |
|
66
|
16 |
|
$config[DaftSource::class]['cacheFile'], |
|
67
|
16 |
|
$config[DaftSource::class]['sources'] |
|
68
|
|
|
) |
|
69
|
|
|
) { |
|
70
|
2 |
|
throw new InvalidArgumentException(sprintf('%s config not found!', DaftSource::class)); |
|
71
|
14 |
|
} elseif ( ! is_string($config[DaftSource::class]['cacheFile'])) { |
|
72
|
2 |
|
throw new InvalidArgumentException(sprintf(self::ERROR_SOURCE_CONFIG, 'cacheFile')); |
|
73
|
12 |
|
} elseif ( ! is_array($config[DaftSource::class]['sources'])) { |
|
74
|
2 |
|
throw new InvalidArgumentException(sprintf(self::ERROR_SOURCE_CONFIG, 'sources')); |
|
75
|
10 |
|
} elseif ( ! $this->FileIsUnderBasePath($config[DaftSource::class]['cacheFile'], false)) { |
|
76
|
2 |
|
throw new InvalidArgumentException(self::ERROR_ROUTER_CACHE_FILE_PATH); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
8 |
|
return parent::ValidateConfig($config); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths