1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Mvc5\Route\Definition; |
7
|
|
|
|
8
|
|
|
use Mvc5\Exception; |
9
|
|
|
use Mvc5\Route\Config; |
10
|
|
|
use Mvc5\Route\Route; |
11
|
|
|
|
12
|
|
|
use function is_array; |
13
|
|
|
|
14
|
|
|
use const Mvc5\{ CLASS_NAME, CONSTRAINTS, HOST, NAME, PATH, REGEX, TOKENS }; |
|
|
|
|
15
|
|
|
|
16
|
|
|
trait Build |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
use Regex; |
22
|
|
|
use Tokens; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param array|Route $route |
26
|
|
|
* @param bool $compile |
27
|
|
|
* @return Route |
28
|
|
|
* @throws \Throwable |
29
|
|
|
*/ |
30
|
32 |
|
protected function build($route, bool $compile = true) : Route |
31
|
|
|
{ |
32
|
32 |
|
return $this->definition($this->create($route), $compile); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array|Route $route |
37
|
|
|
* @return Route |
38
|
|
|
*/ |
39
|
32 |
|
protected function create($route) : Route |
40
|
|
|
{ |
41
|
32 |
|
return $route instanceof Route ? $route : |
42
|
32 |
|
$this->createDefault($route, $route[CLASS_NAME] ?? Config::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param array|\ArrayAccess $route |
47
|
|
|
* @param string $class |
48
|
|
|
* @return Route |
49
|
|
|
*/ |
50
|
12 |
|
protected function createDefault($route = [], string $class = Config::class) : Route |
51
|
|
|
{ |
52
|
12 |
|
return new $class($route); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Route $route |
57
|
|
|
* @param bool $compile |
58
|
|
|
* @return Route |
59
|
|
|
* @throws \Throwable |
60
|
|
|
*/ |
61
|
32 |
|
protected function definition(Route $route, bool $compile = true) : Route |
62
|
|
|
{ |
63
|
|
|
/** @var Route $route */ |
64
|
32 |
|
$route = $this->host($route, $route[HOST]); |
65
|
|
|
|
66
|
32 |
|
if (!isset($route[PATH])) { |
67
|
3 |
|
return isset($route[REGEX]) ? $route : Exception::invalidArgument('Route path not specified'); |
68
|
|
|
} |
69
|
|
|
|
70
|
29 |
|
!isset($route[TOKENS]) && $route = $route->with(TOKENS, $this->tokens( |
71
|
29 |
|
$route[PATH], $route[CONSTRAINTS] ?? [] |
72
|
|
|
)); |
73
|
|
|
|
74
|
29 |
|
$compile && !isset($route[REGEX]) && |
75
|
22 |
|
$route = $route->with(REGEX, $this->regex($route[TOKENS])); |
76
|
|
|
|
77
|
29 |
|
return $route; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param Route $route |
82
|
|
|
* @param array|mixed $host |
83
|
|
|
* @return Route |
84
|
|
|
* @throws \Throwable |
85
|
|
|
*/ |
86
|
32 |
|
protected function host(Route $route, $host) : Route |
87
|
|
|
{ |
88
|
32 |
|
if (!is_array($host)) { |
89
|
31 |
|
return $route; |
90
|
|
|
} |
91
|
|
|
|
92
|
2 |
|
$host[TOKENS] ??= $this->tokens($host[NAME], $host[CONSTRAINTS] ?? []); |
93
|
|
|
|
94
|
2 |
|
$host[REGEX] ??= $this->regex($host[TOKENS]); |
95
|
|
|
|
96
|
2 |
|
return $route->with(HOST, $host); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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