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
|
|
|
implements \Aimeos\MW\Macro\Iface |
23
|
|
|
{ |
24
|
|
|
use \Aimeos\MW\Macro\Traits; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
private $object; |
28
|
|
|
private $context; |
29
|
|
|
private $cond = []; |
30
|
|
|
private $sort = []; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Common initialization for controller classes. |
35
|
|
|
* |
36
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Common MShop context object |
37
|
|
|
*/ |
38
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
39
|
|
|
{ |
40
|
|
|
$this->context = $context; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Adds the given compare, combine or sort expression to the list of expressions |
46
|
|
|
* |
47
|
|
|
* @param \Aimeos\MW\Criteria\Expression\Iface|null $expr Compare, combine or sort expression |
48
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
49
|
|
|
*/ |
50
|
|
|
public function addExpression( \Aimeos\MW\Criteria\Expression\Iface $expr = null ) : Iface |
51
|
|
|
{ |
52
|
|
|
if( $expr instanceof \Aimeos\MW\Criteria\Expression\Sort\Iface ) { |
53
|
|
|
$this->sort[] = $expr; |
54
|
|
|
} elseif( $expr ) { |
55
|
|
|
$this->cond[] = $expr; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the compare and combine expressions added by addExpression() |
64
|
|
|
* |
65
|
|
|
* @return array List of compare and combine expressions |
66
|
|
|
*/ |
67
|
|
|
public function getConditions() : array |
68
|
|
|
{ |
69
|
|
|
return $this->cond; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the compare and combine expressions added by addExpression() |
75
|
|
|
* |
76
|
|
|
* @return array List of sort expressions |
77
|
|
|
*/ |
78
|
|
|
public function getSortations() : array |
79
|
|
|
{ |
80
|
|
|
return $this->sort; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the context object. |
86
|
|
|
* |
87
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object implementing \Aimeos\MShop\Context\Item\Iface |
88
|
|
|
*/ |
89
|
|
|
protected function context() : \Aimeos\MShop\Context\Item\Iface |
90
|
|
|
{ |
91
|
|
|
return $this->context; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the outmost decorator of the decorator stack |
97
|
|
|
* |
98
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Outmost decorator object |
99
|
|
|
*/ |
100
|
|
|
protected function object() : Iface |
101
|
|
|
{ |
102
|
|
|
if( $this->object !== null ) { |
103
|
|
|
return $this->object; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Injects the reference of the outmost object |
112
|
|
|
* |
113
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
114
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
115
|
|
|
*/ |
116
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : Iface |
117
|
|
|
{ |
118
|
|
|
$this->object = $object; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Splits search keys by comma |
125
|
|
|
* |
126
|
|
|
* @param string|null $keys Comma separated string of search keys |
127
|
|
|
* @return array List of search keys |
128
|
|
|
*/ |
129
|
|
|
protected function splitKeys( ?string $keys ) : array |
130
|
|
|
{ |
131
|
|
|
$list = []; |
132
|
|
|
|
133
|
|
|
if( preg_match_all( '/(?P<key>[^(,]+(\(("([^"]|\")*")?[^)]*\))?),?/', (string) $keys, $list ) !== false ) { |
134
|
|
|
return $list['key'] ?? []; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return []; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|