1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||
6 | * @package MW |
||
7 | * @subpackage View |
||
8 | */ |
||
9 | |||
10 | |||
11 | namespace Aimeos\MW\View\Helper\Request; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * View helper class for retrieving request data. |
||
16 | * |
||
17 | * @package MW |
||
18 | * @subpackage View |
||
19 | */ |
||
20 | class Laravel5 |
||
21 | extends \Aimeos\MW\View\Helper\Request\Standard |
||
22 | implements \Aimeos\MW\View\Helper\Request\Iface |
||
23 | { |
||
24 | private $request; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * Initializes the request view helper. |
||
29 | * |
||
30 | * @param \\Aimeos\MW\View\Iface $view View instance with registered view helpers |
||
31 | * @param \Illuminate\Http\Request $request Laravel request object |
||
32 | */ |
||
33 | public function __construct( \Aimeos\MW\View\Iface $view, \Illuminate\Http\Request $request ) |
||
34 | { |
||
35 | $this->request = $request; |
||
36 | |||
37 | parent::__construct( $view, $this->createRequest( $request ) ); |
||
38 | } |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Returns the client IP address. |
||
43 | * |
||
44 | * @return string Client IP address |
||
45 | */ |
||
46 | public function getClientAddress() : string |
||
47 | { |
||
48 | return $this->request->ip(); |
||
49 | } |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Returns the current page or route name |
||
54 | * |
||
55 | * @return string|null Current page or route name |
||
56 | */ |
||
57 | public function getTarget() : ?string |
||
58 | { |
||
59 | if( ( $route = $this->request->route() ) !== null ) { |
||
60 | return $route->getName(); |
||
61 | } |
||
62 | |||
63 | return null; |
||
64 | } |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Transforms a Symfony request into a PSR-7 request object |
||
69 | * |
||
70 | * @param \Illuminate\Http\Request $nativeRequest Laravel request object |
||
71 | * @return \Psr\Http\Message\ServerRequestInterface PSR-7 request object |
||
72 | */ |
||
73 | protected function createRequest( \Illuminate\Http\Request $nativeRequest ) : \Psr\Http\Message\ServerRequestInterface |
||
74 | { |
||
75 | $files = $this->getFiles( $nativeRequest->files->all() ); |
||
76 | $headers = $nativeRequest->headers->all(); |
||
77 | $server = $nativeRequest->server->all(); |
||
78 | $method = $nativeRequest->getMethod(); |
||
79 | $uri = $nativeRequest->getUri(); |
||
80 | |||
81 | $psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
||
0 ignored issues
–
show
|
|||
82 | $request = new \Nyholm\Psr7\ServerRequest( $method, $uri, $headers, $nativeRequest->getContent(), '1.1', $server ); |
||
0 ignored issues
–
show
The type
Nyholm\Psr7\ServerRequest 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
Loading history...
|
|||
83 | $request = $request->withCookieParams( $nativeRequest->cookies->all() ) |
||
84 | ->withParsedBody( $nativeRequest->request->all() ) |
||
85 | ->withQueryParams( $nativeRequest->query->all() ) |
||
86 | ->withUploadedFiles( $files ); |
||
87 | |||
88 | foreach( $nativeRequest->attributes->all() as $key => $value ) { |
||
89 | $request = $request->withAttribute( $key, $value ); |
||
90 | } |
||
91 | |||
92 | return $request; |
||
93 | } |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Converts Symfony uploaded files array to the PSR-7 one. |
||
98 | * |
||
99 | * @param array $files Multi-dimensional list of uploaded files from Symfony request |
||
100 | * @return array Multi-dimensional list of uploaded files as PSR-7 objects |
||
101 | */ |
||
102 | protected function getFiles( array $files ) : array |
||
103 | { |
||
104 | $list = []; |
||
105 | $psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); |
||
106 | |||
107 | foreach( $files as $key => $value ) |
||
108 | { |
||
109 | if( $value instanceof \Symfony\Component\HttpFoundation\File\UploadedFile ) |
||
110 | { |
||
111 | $list[$key] = $psr17Factory->createUploadedFile( |
||
112 | $psr17Factory->createStreamFromFile( $value->getRealPath() ), |
||
113 | $value->getSize(), |
||
114 | $value->getError(), |
||
115 | $value->getClientOriginalName(), |
||
116 | $value->getClientMimeType() |
||
117 | ); |
||
118 | } |
||
119 | elseif( is_array( $value ) ) |
||
120 | { |
||
121 | $list[$key] = $this->getFiles( $value ); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | return $list; |
||
126 | } |
||
127 | } |
||
128 |
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