1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* KNUT7 K7F (https://marciozebedeu.com/) |
5
|
|
|
* KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/) |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @link https://github.com/knut7/framework/ for the canonical source repository |
12
|
|
|
* @copyright (c) 2015. KNUT7 Software Technologies AO Inc. (https://marciozebedeu.com/) |
13
|
|
|
* @license https://marciozebedeu.com/license/new-bsd MIT lIcense |
14
|
|
|
* @author Marcio Zebedeu - [email protected] |
15
|
|
|
* @version 1.0.14 |
16
|
|
|
* |
17
|
|
|
* |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Ballybran\Core\Http; |
21
|
|
|
|
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
23
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
24
|
|
|
|
25
|
|
|
class RouterRequest |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var string $validMethods Valid methods for Router |
29
|
|
|
*/ |
30
|
|
|
protected $validMethods = 'GET|POST|PUT|DELETE|HEAD|OPTIONS|PATCH|ANY|AJAX|XPOST|XPUT|XDELETE|XPATCH'; |
31
|
|
|
/** |
32
|
|
|
* @var Request $request |
33
|
|
|
*/ |
34
|
|
|
private $request; |
35
|
|
|
/** |
36
|
|
|
* @var Response $response |
37
|
|
|
*/ |
38
|
|
|
private $response; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* RouterRequest constructor. |
42
|
|
|
* |
43
|
|
|
* @param Request $request |
44
|
|
|
* @param Response $response |
45
|
|
|
*/ |
46
|
|
|
public function __construct(Request $request, Response $response) |
47
|
|
|
{ |
48
|
|
|
$this->request = $request; |
49
|
|
|
$this->response = $response; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Request |
54
|
|
|
*/ |
55
|
|
|
public function symfonyRequest(): Request |
56
|
|
|
{ |
57
|
|
|
return $this->request; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return Response |
62
|
|
|
*/ |
63
|
|
|
public function symfonyResponse(): Response |
64
|
|
|
{ |
65
|
|
|
return $this->response; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function validMethods(): string |
72
|
|
|
{ |
73
|
|
|
return $this->validMethods; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Request method validation |
78
|
|
|
* |
79
|
|
|
* @param string $data |
80
|
|
|
* @param string $method |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function validMethod(string $data, string $method): bool |
85
|
|
|
{ |
86
|
|
|
$valid = false; |
87
|
|
|
if (strstr($data, '|')) { |
88
|
|
|
foreach (explode('|', $data) as $value) { |
89
|
|
|
$valid = $this->checkMethods($value, $method); |
90
|
|
|
if ($valid) { |
91
|
|
|
break; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} else { |
95
|
|
|
$valid = $this->checkMethods($data, $method); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $valid; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the request method used, taking overrides into account |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getMethod(): string |
107
|
|
|
{ |
108
|
|
|
$method = $this->request->getMethod(); |
109
|
|
|
$formMethod = $this->request->request->get('_method'); |
110
|
|
|
if (!empty($formMethod)) { |
111
|
|
|
$method = strtoupper($formMethod); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $method; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* check method valid |
119
|
|
|
* |
120
|
|
|
* @param string $value |
121
|
|
|
* @param string $method |
122
|
|
|
* |
123
|
|
|
* @return bool |
124
|
|
|
*/ |
125
|
|
|
protected function checkMethods(string $value, string $method): bool |
126
|
|
|
{ |
127
|
|
|
if (in_array($value, explode('|', $this->validMethods))) { |
128
|
|
|
if ($this->request->isXmlHttpRequest() && $value === 'AJAX') { |
129
|
|
|
return true; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if ($this->request->isXmlHttpRequest() && strpos($value, 'X') === 0 |
133
|
|
|
&& $method === ltrim($value, 'X')) { |
134
|
|
|
return true; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (in_array($value, [$method, 'ANY'])) { |
138
|
|
|
return true; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return false; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
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