Passed
Push — master ( df26ff...31fd68 )
by Aimeos
02:28
created

Base::getConditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 * @package Controller
8
 * @subpackage Frontend
9
 */
10
11
12
namespace Aimeos\Controller\Frontend;
13
14
15
/**
16
 * Common methods for frontend controller classes.
17
 *
18
 * @package Controller
19
 * @subpackage Frontend
20
 */
21
abstract class Base
22
{
23
	private $object;
24
	private $context;
25
	private $cond = [];
26
	private $sort = [];
27
28
29
	/**
30
	 * Common initialization for controller classes.
31
	 *
32
	 * @param \Aimeos\MShop\Context\Item\Iface $context Common MShop context object
33
	 */
34
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
35
	{
36
		$this->context = $context;
37
	}
38
39
40
	/**
41
	 * Catch unknown methods
42
	 *
43
	 * @param string $name Name of the method
44
	 * @param array $param List of method parameter
45
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
46
	 */
47
	public function __call( string $name, array $param )
48
	{
49
		throw new \Aimeos\Controller\Frontend\Exception( sprintf( 'Unable to call method "%1$s"', $name ) );
50
	}
51
52
53
	/**
54
	 * Adds the given compare, combine or sort expression to the list of expressions
55
	 *
56
	 * @param \Aimeos\MW\Criteria\Expression\Iface $expr Compare, combine or sort expression
57
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
58
	 */
59
	public function addExpression( \Aimeos\MW\Criteria\Expression\Iface $expr ) : Iface
60
	{
61
		if( $expr instanceof \Aimeos\MW\Criteria\Expression\Sort\Iface ) {
62
			$this->sort[] = $expr;
63
		} else {
64
			$this->cond[] = $expr;
65
		}
66
67
		return $this;
68
	}
69
70
71
	/**
72
	 * Returns the compare and combine expressions added by addExpression()
73
	 *
74
	 * @return array List of compare and combine expressions
75
	 */
76
	public function getConditions() : array
77
	{
78
		return $this->cond;
79
	}
80
81
82
	/**
83
	 * Returns the compare and combine expressions added by addExpression()
84
	 *
85
	 * @return array List of sort expressions
86
	 */
87
	public function getSortations() : array
88
	{
89
		return $this->sort;
90
	}
91
92
93
	/**
94
	 * Returns the context object.
95
	 *
96
	 * @return \Aimeos\MShop\Context\Item\Iface Context object implementing \Aimeos\MShop\Context\Item\Iface
97
	 */
98
	protected function getContext() : \Aimeos\MShop\Context\Item\Iface
99
	{
100
		return $this->context;
101
	}
102
103
104
	/**
105
	 * Returns the outmost decorator of the decorator stack
106
	 *
107
	 * @return \Aimeos\Controller\Frontend\Iface Outmost decorator object
108
	 */
109
	protected function getObject() : Iface
110
	{
111
		if( $this->object !== null ) {
112
			return $this->object;
113
		}
114
115
		return $this;
116
	}
117
118
119
	/**
120
	 * Injects the reference of the outmost object
121
	 *
122
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
123
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
124
	 */
125
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : Iface
126
	{
127
		$this->object = $object;
128
		return $this;
129
	}
130
}
131