Passed
Push — master ( 388e81...5f90b3 )
by Aimeos
05:18
created

Base::view()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 * @package MW
8
 * @subpackage View
9
 */
10
11
12
namespace Aimeos\MW\View\Helper;
13
14
15
/**
16
 * Common abstract class for all view helper classes.
17
 *
18
 * @method string|array config(string $name = null, string|array $default = null) Returns the config value for the given key
19
 * @method \Aimeos\MW\View\Helper\Iface csrf() Returns the CSRF helper object
20
 * @method string date(string $date) Returns the formatted date
21
 * @method \Aimeos\MW\View\Helper\Iface encoder() Returns the encoder helper object
22
 * @method string formparam(string|array $names) Returns the name for the HTML form parameter
23
 * @method \Aimeos\MW\Mail\Message\Iface mail() Returns the e-mail message object
24
 * @method string number(integer|float|decimal $number, integer $decimals = 2) Returns the formatted number
25
 * @method string|array param(string|null $name, string|array $default) Returns the parameter value
26
 * @method string partial(string $filepath, array $params = [] ) Renders the partial template
27
 * @method \Aimeos\MW\View\Helper\Iface request() Returns the request helper object
28
 * @method string translate(string $domain, string $singular, string $plural = '', integer $number = 1) Returns the translated string or the original one if no translation is available
29
 * @method string url(string|null $target, string|null $controller = null, string|null $action = null, array $params = [], array $trailing = [], array $config = []) Returns the URL assembled from the given arguments
30
 *
31
 * @package MW
32
 * @subpackage View
33
 */
34
abstract class Base
35
{
36
	private $view;
37
38
39
	/**
40
	 * Initializes the view helper classes.
41
	 *
42
	 * @param \Aimeos\MW\View\Iface $view View instance with registered view helpers
43
	 */
44
	public function __construct( \Aimeos\MW\View\Iface $view )
45
	{
46
		$this->view = $view;
47
	}
48
49
50
	/**
51
	 * Calls the view helper with the given name and arguments and returns it's output.
52
	 *
53
	 * @param string $name Name of the view helper
54
	 * @param array $args Arguments passed to the view helper
55
	 * @return mixed Output depending on the view helper
56
	 */
57
	public function __call( string $name, array $args )
58
	{
59
		return call_user_func_array( array( $this->view, $name ), $args );
60
	}
61
62
63
	/**
64
	 * Sets a new view object for changing views afterwards
65
	 *
66
	 * @param \Aimeos\MW\View\Iface $view View object
67
	 * @return \Aimeos\MW\View\Helper\Iface Helper object for method chaining
68
	 */
69
	public function setView( \Aimeos\MW\View\Iface $view ) : Iface
70
	{
71
		$this->view = $view;
72
		return $this;
73
	}
74
75
76
	/**
77
	 * Returns the view object.
78
	 *
79
	 * @return \Aimeos\MW\View\Iface View object
80
	 */
81
	protected function view() : \Aimeos\MW\View\Iface
82
	{
83
		return $this->view;
84
	}
85
}
86