Passed
Push — master ( c9dfc7...a4ce90 )
by Aimeos
01:38
created

Base::type()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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( $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( $operator, $key, $value )
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( $code )
83
	{
84
		return $this->controller->find( $code );
85
	}
86
87
88
	/**
89
	 * Returns the service for the given ID
90
	 *
91
	 * @param string $id Unique service ID
92
	 * @return \Aimeos\MShop\Service\Item\Iface Service item including the referenced domains items
93
	 * @since 2019.04
94
	 */
95
	public function get( $id )
96
	{
97
		return $this->controller->get( $id );
98
	}
99
100
101
	/**
102
	 * Returns the service item for the given ID
103
	 *
104
	 * @param string $serviceId Unique service ID
105
	 * @return \Aimeos\MShop\Service\Provider\Iface Service provider object
106
	 */
107
	public function getProvider( $serviceId )
108
	{
109
		return $this->controller->getProvider( $serviceId );
110
	}
111
112
113
	/**
114
	 * Returns the service providers for the given type
115
	 *
116
	 * @return \Aimeos\MShop\Service\Provider\Iface[] List of service IDs as keys and service provider objects as values
117
	 */
118
	public function getProviders()
119
	{
120
		return $this->controller->getProviders();
121
	}
122
123
124
	/**
125
	 * Parses the given array and adds the conditions to the list of conditions
126
	 *
127
	 * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['service.status' => 0]], ['==' => ['service.type' => 'default']]]]
128
	 * @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface
129
	 * @since 2019.04
130
	 */
131
	public function parse( array $conditions )
132
	{
133
		$this->controller->parse( $conditions );
134
		return $this;
135
	}
136
137
138
	/**
139
	 * Processes the service for the given order, e.g. payment and delivery services
140
	 *
141
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order which should be processed
142
	 * @param string $serviceId Unique service item ID
143
	 * @param array $urls Associative list of keys and the corresponding URLs
144
	 * 	(keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment")
145
	 * @param array $params Request parameters and order service attributes
146
	 * @return \Aimeos\MShop\Common\Helper\Form\Iface|null Form object with URL, parameters, etc.
147
	 * 	or null if no form data is required
148
	 */
149
	public function process( \Aimeos\MShop\Order\Item\Iface $orderItem, $serviceId, array $urls, array $params )
150
	{
151
		return $this->controller->process( $orderItem, $serviceId, $urls, $params );
152
	}
153
154
	/**
155
	 * Returns the services filtered by the previously assigned conditions
156
	 *
157
	 * @param integer &$total Parameter where the total number of found services will be stored in
158
	 * @return \Aimeos\MShop\Service\Item\Iface[] Ordered list of service items
159
	 * @since 2019.04
160
	 */
161
	public function search( &$total = null )
162
	{
163
		return $this->controller->search( $total );
164
	}
165
166
167
	/**
168
	 * Sets the start value and the number of returned services for slicing the list of found services
169
	 *
170
	 * @param integer $start Start value of the first attribute in the list
171
	 * @param integer $limit Number of returned services
172
	 * @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface
173
	 * @since 2019.04
174
	 */
175
	public function slice( $start, $limit )
176
	{
177
		$this->controller->slice( $start, $limit );
178
		return $this;
179
	}
180
181
182
	/**
183
	 * Sets the sorting of the result list
184
	 *
185
	 * @param string|null $key Sorting of the result list like "position", null for no sorting
186
	 * @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface
187
	 * @since 2019.04
188
	 */
189
	public function sort( $key = null )
190
	{
191
		$this->controller->sort( $key );
192
		return $this;
193
	}
194
195
196
	/**
197
	 * Adds attribute types for filtering
198
	 *
199
	 * @param array|string $code Service type or list of types
200
	 * @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface
201
	 * @since 2019.04
202
	 */
203
	public function type( $code )
204
	{
205
		$this->controller->type( $code );
206
		return $this;
207
	}
208
209
210
	/**
211
	 * Updates the order status sent by payment gateway notifications
212
	 *
213
	 * @param ServerRequestInterface $request Request object
214
	 * @param ResponseInterface $response Response object that will contain HTTP status and response body
215
	 * @param string $code Unique code of the service used for the current order
216
	 * @return \Psr\Http\Message\ResponseInterface Response object
217
	 */
218
	public function updatePush( ServerRequestInterface $request, ResponseInterface $response, $code )
219
	{
220
		return $this->controller->updatePush( $request, $response, $code );
221
	}
222
223
224
	/**
225
	 * Updates the payment or delivery status for the given request
226
	 *
227
	 * @param ServerRequestInterface $request Request object with parameters and request body
228
	 * @param string $code Unique code of the service used for the current order
229
	 * @param string $orderid ID of the order whose payment status should be updated
230
	 * @return \Aimeos\MShop\Order\Item\Iface $orderItem Order item that has been updated
231
	 */
232
	public function updateSync( ServerRequestInterface $request, $code, $orderid )
233
	{
234
		return $this->controller->updateSync( $request, $code, $orderid );
235
	}
236
237
238
	/**
239
	 * Sets the referenced domains that will be fetched too when retrieving items
240
	 *
241
	 * @param array $domains Domain names of the referenced items that should be fetched too
242
	 * @return \Aimeos\Controller\Frontend\Service\Iface Service controller for fluent interface
243
	 * @since 2019.04
244
	 */
245
	public function uses( array $domains )
246
	{
247
		$this->controller->uses( $domains );
248
		return $this;
249
	}
250
251
252
	/**
253
	 * Returns the frontend controller
254
	 *
255
	 * @return \Aimeos\Controller\Frontend\Service\Iface Frontend controller object
256
	 */
257
	protected function getController()
258
	{
259
		return $this->controller;
260
	}
261
}
262