Completed
Push — master ( 3864d9...55fd67 )
by Aimeos
08:54
created

Laravel5::getClientAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015
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\Base
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 "Base" and comma; 1 found
Loading history...
22
	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...
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 )
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
34
	{
35
		parent::__construct( $view );
36
37
		$this->request = $request;
38
	}
39
40
41
	/**
42
	 * Returns the request view helper.
43
	 *
44
	 * @return \Aimeos\MW\View\Helper\Iface Request view helper
45
	 */
46
	public function transform()
47
	{
48
		return $this;
49
	}
50
51
52
	/**
53
	 * Returns the request body.
54
	 *
55
	 * @return string Request body
56
	 */
57
	public function getBody()
58
	{
59
		return $this->request->getContent();
60
	}
61
62
63
	/**
64
	 * Returns the client IP address.
65
	 *
66
	 * @return string Client IP address
67
	 */
68
	public function getClientAddress()
69
	{
70
		return $this->request->ip();
71
	}
72
73
74
	/**
75
	 * Returns the current page or route name
76
	 *
77
	 * @return string|null Current page or route name
78
	 */
79
	public function getTarget()
80
	{
81
		if( ( $route = $this->request->route() ) !== null ) {
82
			return $route->getName();
83
		}
84
	}
85
}
86