1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace Hhxsv5\LaravelS\Swoole; |
||
4 | |||
5 | use Illuminate\Http\Request as IlluminateRequest; |
||
0 ignored issues
–
show
The type
Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
6 | use Swoole\Http\Request as SwooleRequest; |
||
7 | use Symfony\Component\HttpFoundation\ParameterBag; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\ParameterBag was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | |||
9 | class Request |
||
0 ignored issues
–
show
|
|||
10 | { |
||
11 | protected $swooleRequest; |
||
12 | |||
13 | public function __construct(SwooleRequest $request) |
||
0 ignored issues
–
show
|
|||
14 | { |
||
15 | $this->swooleRequest = $request; |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * Convert SwooleRequest to IlluminateRequest |
||
20 | * @param array $rawServer |
||
0 ignored issues
–
show
|
|||
21 | * @param array $rawEnv |
||
0 ignored issues
–
show
|
|||
22 | * @return IlluminateRequest |
||
0 ignored issues
–
show
|
|||
23 | */ |
||
24 | public function toIlluminateRequest(array $rawServer = [], array $rawEnv = []) |
||
25 | { |
||
26 | $__GET = isset($this->swooleRequest->get) ? $this->swooleRequest->get : []; |
||
27 | $__POST = isset($this->swooleRequest->post) ? $this->swooleRequest->post : []; |
||
28 | $__COOKIE = isset($this->swooleRequest->cookie) ? $this->swooleRequest->cookie : []; |
||
29 | $server = isset($this->swooleRequest->server) ? $this->swooleRequest->server : []; |
||
30 | $headers = isset($this->swooleRequest->header) ? $this->swooleRequest->header : []; |
||
31 | $__FILES = isset($this->swooleRequest->files) ? $this->swooleRequest->files : []; |
||
32 | $__CONTENT = empty($__FILES) ? $this->swooleRequest->rawContent() : ''; // Cannot call rawContent() to avoid double the file memory when uploading a file. |
||
33 | $_REQUEST = []; |
||
34 | $_SESSION = []; |
||
35 | |||
36 | static $headerServerMapping = [ |
||
37 | 'x-real-ip' => 'REMOTE_ADDR', |
||
38 | 'x-real-port' => 'REMOTE_PORT', |
||
39 | 'server-protocol' => 'SERVER_PROTOCOL', |
||
40 | 'server-name' => 'SERVER_NAME', |
||
41 | 'server-addr' => 'SERVER_ADDR', |
||
42 | 'server-port' => 'SERVER_PORT', |
||
43 | 'scheme' => 'REQUEST_SCHEME', |
||
44 | ]; |
||
45 | |||
46 | $_ENV = $rawEnv; |
||
47 | $_SERVER = $rawServer; |
||
48 | foreach ($headers as $key => $value) { |
||
49 | // Fix client && server's info |
||
50 | if (isset($headerServerMapping[$key])) { |
||
51 | $server[$headerServerMapping[$key]] = $value; |
||
52 | } else { |
||
53 | $key = str_replace('-', '_', $key); |
||
54 | $server['http_' . $key] = $value; |
||
55 | } |
||
56 | } |
||
57 | $server = array_change_key_case($server, CASE_UPPER); |
||
58 | $_SERVER = array_merge($_SERVER, $server); |
||
59 | if (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') { |
||
60 | $_SERVER['HTTPS'] = 'on'; |
||
61 | } |
||
62 | |||
63 | // Fix REQUEST_URI with QUERY_STRING |
||
64 | if (strpos($_SERVER['REQUEST_URI'], '?') === false |
||
65 | && isset($_SERVER['QUERY_STRING']) |
||
66 | && $_SERVER['QUERY_STRING'] !== '' |
||
67 | ) { |
||
68 | $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
||
69 | } |
||
70 | |||
71 | // Fix argv & argc |
||
72 | if (!isset($_SERVER['argv'])) { |
||
73 | $_SERVER['argv'] = isset($GLOBALS['argv']) ? $GLOBALS['argv'] : []; |
||
74 | $_SERVER['argc'] = isset($GLOBALS['argc']) ? $GLOBALS['argc'] : 0; |
||
75 | } |
||
76 | |||
77 | // Initialize laravel request |
||
78 | IlluminateRequest::enableHttpMethodParameterOverride(); |
||
79 | $request = IlluminateRequest::createFromBase(new \Symfony\Component\HttpFoundation\Request($__GET, $__POST, [], $__COOKIE, $__FILES, $_SERVER, $__CONTENT)); |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
80 | |||
81 | if (0 === strpos($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') |
||
82 | && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH']) |
||
83 | ) { |
||
84 | parse_str($request->getContent(), $data); |
||
85 | $request->request = new ParameterBag($data); |
||
86 | } |
||
87 | |||
88 | return $request; |
||
89 | } |
||
90 | } |
||
91 |