Flow   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getClientAddress() 0 3 1
A __construct() 0 7 1
A createRequest() 0 13 1
A getTarget() 0 3 1
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
use Zend\Diactoros\ServerRequestFactory;
14
use Zend\Diactoros\ServerRequest;
15
use Zend\Diactoros\Stream;
16
17
18
/**
19
 * View helper class for accessing request data from Flow
20
 *
21
 * @package MW
22
 * @subpackage View
23
 */
24
class Flow
25
	extends \Aimeos\MW\View\Helper\Request\Standard
26
	implements \Aimeos\MW\View\Helper\Request\Iface
27
{
28
	private $request;
29
30
31
	/**
32
	 * Initializes the request view helper.
33
	 *
34
	 * @param \\Aimeos\MW\View\Iface $view View instance with registered view helpers
0 ignored issues
show
Bug introduced by
The type \Aimeos\MW\View\Iface 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
	 * @param \Neos\Flow\Http\Request $request Flow request object
36
	 * @param array $files List of uploaded files like in $_FILES
37
	 * @param array $query List of uploaded files like in $_GET
38
	 * @param array $post List of uploaded files like in $_POST
39
	 * @param array $cookies List of uploaded files like in $_COOKIES
40
	 * @param array $server List of uploaded files like in $_SERVER
41
	 */
42
	public function __construct( \Aimeos\MW\View\Iface $view, \Neos\Flow\Http\Request $request, array $files = [],
43
		array $query = [], array $post = [], array $cookies = [], array $server = [] )
44
	{
45
		$this->request = $request;
46
		$psr7request = $this->createRequest( $request, $files, $query, $post, $cookies, $server );
47
48
		parent::__construct( $view, $psr7request );
49
	}
50
51
52
	/**
53
	 * Returns the client IP address.
54
	 *
55
	 * @return string Client IP address
56
	 */
57
	public function getClientAddress() : string
58
	{
59
		return $this->request->getClientIpAddress();
60
	}
61
62
63
	/**
64
	 * Returns the current page or route name
65
	 *
66
	 * @return string|null Current page or route name
67
	 */
68
	public function getTarget() : ?string
69
	{
70
		return null;
71
	}
72
73
74
	/**
75
	 * Creates a PSR-7 compatible request
76
	 *
77
	 * @param \Neos\Flow\Http\Request $nativeRequest Flow request object
78
	 * @param array $files List of uploaded files like in $_FILES
79
	 * @param array $query List of uploaded files like in $_GET
80
	 * @param array $post List of uploaded files like in $_POST
81
	 * @param array $cookies List of uploaded files like in $_COOKIES
82
	 * @param array $server List of uploaded files like in $_SERVER
83
	 * @return \Psr\Http\Message\ServerRequestInterface PSR-7 request object
84
	 */
85
	protected function createRequest( \Neos\Flow\Http\Request $nativeRequest, array $files,
86
		array $query, array $post, array $cookies, array $server ) : \Psr\Http\Message\ServerRequestInterface
87
	{
88
		$server = ServerRequestFactory::normalizeServer( $server );
89
		$files = ServerRequestFactory::normalizeFiles( $files );
90
		$headers = $nativeRequest->getHeaders()->getAll();
91
		$uri = (string) $nativeRequest->getUri();
92
		$method = $nativeRequest->getMethod();
93
94
		$body = new Stream('php://temp', 'wb+');
95
		$body->write( $nativeRequest->getContent() );
96
97
		return new ServerRequest( $server, $files, $uri, $method, $body, $headers, $cookies, $query, $post );
98
	}
99
}
100