1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2018 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Service\Decorator; |
12
|
|
|
|
13
|
|
|
use \Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
use \Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Base for service frontend controller decorators |
19
|
|
|
* |
20
|
|
|
* @package Controller |
21
|
|
|
* @subpackage Frontend |
22
|
|
|
*/ |
23
|
|
|
abstract class Base |
24
|
|
|
extends \Aimeos\Controller\Frontend\Base |
25
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Service\Iface |
26
|
|
|
{ |
27
|
|
|
private $controller; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initializes the controller decorator. |
32
|
|
|
* |
33
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
34
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
35
|
|
|
*/ |
36
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
37
|
|
|
{ |
38
|
|
|
parent::__construct( $context ); |
39
|
|
|
|
40
|
|
|
$iface = \Aimeos\Controller\Frontend\Service\Iface::class; |
41
|
|
|
$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Passes unknown methods to wrapped objects. |
47
|
|
|
* |
48
|
|
|
* @param string $name Name of the method |
49
|
|
|
* @param array $param List of method parameter |
50
|
|
|
* @return mixed Returns the value of the called method |
51
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
52
|
|
|
*/ |
53
|
|
|
public function __call( string $name, array $param ) |
54
|
|
|
{ |
55
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Adds generic condition for filtering services |
61
|
|
|
* |
62
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
63
|
|
|
* @param string $key Search key defined by the service manager, e.g. "service.status" |
64
|
|
|
* @param array|string $value Value or list of values to compare to |
65
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface |
66
|
|
|
* @since 2019.04 |
67
|
|
|
*/ |
68
|
|
|
public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Service\Iface |
69
|
|
|
{ |
70
|
|
|
$this->controller->compare( $operator, $key, $value ); |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the service for the given code |
77
|
|
|
* |
78
|
|
|
* @param string $code Unique service code |
79
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface Service item including the referenced domains items |
80
|
|
|
* @since 2019.04 |
81
|
|
|
*/ |
82
|
|
|
public function find( string $code ) : \Aimeos\MShop\Service\Item\Iface |
83
|
|
|
{ |
84
|
|
|
return $this->controller->find( $code ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Creates a search function string for the given name and parameters |
90
|
|
|
* |
91
|
|
|
* @param string $name Name of the search function without parenthesis, e.g. "service:has" |
92
|
|
|
* @param array $params List of parameters for the search function with numeric keys starting at 0 |
93
|
|
|
* @return string Search function string that can be used in compare() |
94
|
|
|
*/ |
95
|
|
|
public function function( string $name, array $params ) : string |
96
|
|
|
{ |
97
|
|
|
return $this->controller->function( $name, $params ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns the service for the given ID |
103
|
|
|
* |
104
|
|
|
* @param string $id Unique service ID |
105
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface Service item including the referenced domains items |
106
|
|
|
* @since 2019.04 |
107
|
|
|
*/ |
108
|
|
|
public function get( string $id ) : \Aimeos\MShop\Service\Item\Iface |
109
|
|
|
{ |
110
|
|
|
return $this->controller->get( $id ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns the service item for the given ID |
116
|
|
|
* |
117
|
|
|
* @param string $serviceId Unique service ID |
118
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface Service provider object |
119
|
|
|
*/ |
120
|
|
|
public function getProvider( string $serviceId ) : \Aimeos\MShop\Service\Provider\Iface |
121
|
|
|
{ |
122
|
|
|
return $this->controller->getProvider( $serviceId ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns the service providers for the given type |
128
|
|
|
* |
129
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface[] List of service IDs as keys and service provider objects as values |
130
|
|
|
*/ |
131
|
|
|
public function getProviders() |
132
|
|
|
{ |
133
|
|
|
return $this->controller->getProviders(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
139
|
|
|
* |
140
|
|
|
* @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['service.status' => 0]], ['==' => ['service.type' => 'default']]]] |
141
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface |
142
|
|
|
* @since 2019.04 |
143
|
|
|
*/ |
144
|
|
|
public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Service\Iface |
145
|
|
|
{ |
146
|
|
|
$this->controller->parse( $conditions ); |
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Processes the service for the given order, e.g. payment and delivery services |
153
|
|
|
* |
154
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order which should be processed |
155
|
|
|
* @param string $serviceId Unique service item ID |
156
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
157
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
158
|
|
|
* @param array $params Request parameters and order service attributes |
159
|
|
|
* @return \Aimeos\MShop\Common\Helper\Form\Iface|null Form object with URL, parameters, etc. |
160
|
|
|
* or null if no form data is required |
161
|
|
|
*/ |
162
|
|
|
public function process( \Aimeos\MShop\Order\Item\Iface $orderItem, string $serviceId, |
163
|
|
|
array $urls, array $params ) : ?\Aimeos\MShop\Common\Helper\Form\Iface |
164
|
|
|
{ |
165
|
|
|
return $this->controller->process( $orderItem, $serviceId, $urls, $params ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns the services filtered by the previously assigned conditions |
170
|
|
|
* |
171
|
|
|
* @param int &$total Parameter where the total number of found services will be stored in |
172
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface[] Ordered list of service items |
173
|
|
|
* @since 2019.04 |
174
|
|
|
*/ |
175
|
|
|
public function search( int &$total = null ) |
176
|
|
|
{ |
177
|
|
|
return $this->controller->search( $total ); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Sets the start value and the number of returned services for slicing the list of found services |
183
|
|
|
* |
184
|
|
|
* @param int $start Start value of the first attribute in the list |
185
|
|
|
* @param int $limit Number of returned services |
186
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface |
187
|
|
|
* @since 2019.04 |
188
|
|
|
*/ |
189
|
|
|
public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Service\Iface |
190
|
|
|
{ |
191
|
|
|
$this->controller->slice( $start, $limit ); |
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Sets the sorting of the result list |
198
|
|
|
* |
199
|
|
|
* @param string|null $key Sorting of the result list like "position", null for no sorting |
200
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface |
201
|
|
|
* @since 2019.04 |
202
|
|
|
*/ |
203
|
|
|
public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Service\Iface |
204
|
|
|
{ |
205
|
|
|
$this->controller->sort( $key ); |
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Adds attribute types for filtering |
212
|
|
|
* |
213
|
|
|
* @param array|string $code Service type or list of types |
214
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface |
215
|
|
|
* @since 2019.04 |
216
|
|
|
*/ |
217
|
|
|
public function type( $code ) : \Aimeos\Controller\Frontend\Service\Iface |
218
|
|
|
{ |
219
|
|
|
$this->controller->type( $code ); |
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Updates the order status sent by payment gateway notifications |
226
|
|
|
* |
227
|
|
|
* @param ServerRequestInterface $request Request object |
228
|
|
|
* @param ResponseInterface $response Response object that will contain HTTP status and response body |
229
|
|
|
* @param string $code Unique code of the service used for the current order |
230
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object |
231
|
|
|
*/ |
232
|
|
|
public function updatePush( ServerRequestInterface $request, ResponseInterface $response, string $code ) : \Psr\Http\Message\ResponseInterface |
233
|
|
|
{ |
234
|
|
|
return $this->controller->updatePush( $request, $response, $code ); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Updates the payment or delivery status for the given request |
240
|
|
|
* |
241
|
|
|
* @param ServerRequestInterface $request Request object with parameters and request body |
242
|
|
|
* @param string $code Unique code of the service used for the current order |
243
|
|
|
* @param string $orderid ID of the order whose payment status should be updated |
244
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface $orderItem Order item that has been updated |
245
|
|
|
*/ |
246
|
|
|
public function updateSync( ServerRequestInterface $request, string $code, string $orderid ) : \Aimeos\MShop\Order\Item\Iface |
247
|
|
|
{ |
248
|
|
|
return $this->controller->updateSync( $request, $code, $orderid ); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Sets the referenced domains that will be fetched too when retrieving items |
254
|
|
|
* |
255
|
|
|
* @param array $domains Domain names of the referenced items that should be fetched too |
256
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface |
257
|
|
|
* @since 2019.04 |
258
|
|
|
*/ |
259
|
|
|
public function uses( array $domains ) : \Aimeos\Controller\Frontend\Service\Iface |
260
|
|
|
{ |
261
|
|
|
$this->controller->uses( $domains ); |
262
|
|
|
|
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Injects the reference of the outmost object |
269
|
|
|
* |
270
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
271
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
272
|
|
|
*/ |
273
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface |
274
|
|
|
{ |
275
|
|
|
parent::setObject( $object ); |
276
|
|
|
|
277
|
|
|
$this->controller->setObject( $object ); |
278
|
|
|
|
279
|
|
|
return $this; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Returns the frontend controller |
285
|
|
|
* |
286
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Frontend controller object |
287
|
|
|
*/ |
288
|
|
|
protected function getController() : \Aimeos\Controller\Frontend\Service\Iface |
289
|
|
|
{ |
290
|
|
|
return $this->controller; |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|