Completed
Push — master ( 2137d2...4a0d68 )
by Aimeos
10:40
created

Flow::createRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 6
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2016
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
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Standard" and comma; 1 found
Loading history...
26
	implements \Aimeos\MW\View\Helper\Request\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
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
35
	 * @param \TYPO3\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, \TYPO3\Flow\Http\Request $request, array $files = array(),
43
		array $query = array(), array $post = array(), array $cookies = array(), array $server = array() )
44
	{
45
		$this->request = $request;
46
		$psr7request = $this->createRequest( $request, $files, $query, $post, $cookies, $server );
47
48
		\Aimeos\MW\View\Helper\Base::__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()
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()
69
	{
70
		return null;
71
	}
72
73
74
	/**
75
	 * Creates a PSR-7 compatible request
76
	 *
77
	 * @param \TYPO3\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( \TYPO3\Flow\Http\Request $nativeRequest, array $files,
86
		array $query, array $post, array $cookies, array $server )
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() );
0 ignored issues
show
Bug introduced by
It seems like $nativeRequest->getContent() targeting TYPO3\Flow\Http\Request::getContent() can also be of type resource; however, Zend\Diactoros\Stream::write() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
96
97
		return new ServerRequest( $server, $files, $uri, $method, $body, $headers, $cookies, $query, $post );
98
	}
99
}
100