Passed
Push — master ( ee42b0...a87169 )
by Aimeos
07:53
created

Base::cancel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
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), 2018-2022
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Subscription\Decorator;
12
13
14
/**
15
 * Base for subscription frontend controller decorators
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
abstract class Base
21
	extends \Aimeos\Controller\Frontend\Base
22
	implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Subscription\Iface
23
{
24
	use \Aimeos\Controller\Frontend\Common\Decorator\Traits;
25
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\Subscription\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
	 * Clones objects in controller and resets values
61
	 */
62
	public function __clone()
63
	{
64
		$this->controller = clone $this->controller;
65
	}
66
67
68
	/**
69
	 * Cancels an active subscription
70
	 *
71
	 * @param string $id Unique subscription ID
72
	 * @return \Aimeos\MShop\Subscription\Item\Iface Canceled subscription item
73
	 */
74
	public function cancel( string $id ) : \Aimeos\MShop\Subscription\Item\Iface
75
	{
76
		return $this->controller->cancel( $id );
77
	}
78
79
80
	/**
81
	 * Adds generic condition for filtering
82
	 *
83
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
84
	 * @param string $key Search key defined by the subscription manager, e.g. "subscription.status"
85
	 * @param array|string $value Value or list of values to compare to
86
	 * @return \Aimeos\Controller\Frontend\Subscription\Iface Subscription controller for fluent interface
87
	 * @since 2019.04
88
	 */
89
	public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Subscription\Iface
90
	{
91
		$this->controller->compare( $operator, $key, $value );
92
		return $this;
93
	}
94
95
96
	/**
97
	 * Returns the subscription for the given subscription ID
98
	 *
99
	 * @param string $id Unique subscription ID
100
	 * @return \Aimeos\MShop\Subscription\Item\Iface Subscription item including the referenced domains items
101
	 * @since 2019.04
102
	 */
103
	public function get( string $id ) : \Aimeos\MShop\Subscription\Item\Iface
104
	{
105
		return $this->controller->get( $id );
106
	}
107
108
109
	/**
110
	 * Returns the available interval attribute items
111
	 *
112
	 * @return \Aimeos\Map Associative list of intervals as keys and items implementing \Aimeos\MShop\Attribute\Item\Iface
113
	 */
114
	public function getIntervals() : \Aimeos\Map
115
	{
116
		return $this->controller->getIntervals();
117
	}
118
119
120
	/**
121
	 * Parses the given array and adds the conditions to the list of conditions
122
	 *
123
	 * @param array $conditions List of conditions, e.g. ['>' => ['subscription.interval' => 'P0Y1M0W0D']]
124
	 * @return \Aimeos\Controller\Frontend\Subscription\Iface Subscription controller for fluent interface
125
	 * @since 2019.04
126
	 */
127
	public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Subscription\Iface
128
	{
129
		$this->controller->parse( $conditions );
130
		return $this;
131
	}
132
133
134
	/**
135
	 * Saves the modified subscription item
136
	 *
137
	 * @param \Aimeos\MShop\Subscription\Item\Iface $item Subscription object
138
	 * @return \Aimeos\MShop\Subscription\Item\Iface Saved subscription item
139
	 */
140
	public function save( \Aimeos\MShop\Subscription\Item\Iface $item ) : \Aimeos\MShop\Subscription\Item\Iface
141
	{
142
		return $this->controller->save( $item );
143
	}
144
145
146
	/**
147
	 * Returns the subscriptions filtered by the previously assigned conditions
148
	 *
149
	 * @param int &$total Parameter where the total number of found subscriptions will be stored in
150
	 * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Subscription\Item\Iface
151
	 * @since 2019.04
152
	 */
153
	public function search( int &$total = null ) : \Aimeos\Map
154
	{
155
		return $this->controller->search( $total );
156
	}
157
158
159
	/**
160
	 * Sets the start value and the number of returned subscription items for slicing the list of found subscription items
161
	 *
162
	 * @param int $start Start value of the first subscription item in the list
163
	 * @param int $limit Number of returned subscription items
164
	 * @return \Aimeos\Controller\Frontend\Subscription\Iface Subscription controller for fluent interface
165
	 * @since 2019.04
166
	 */
167
	public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Subscription\Iface
168
	{
169
		$this->controller->slice( $start, $limit );
170
		return $this;
171
	}
172
173
174
	/**
175
	 * Sets the sorting of the result list
176
	 *
177
	 * @param string|null $key Sorting key of the result list like "interval", null for no sorting
178
	 * @return \Aimeos\Controller\Frontend\Subscription\Iface Subscription controller for fluent interface
179
	 * @since 2019.04
180
	 */
181
	public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Subscription\Iface
182
	{
183
		$this->controller->sort( $key );
184
		return $this;
185
	}
186
187
188
	/**
189
	 * Injects the reference of the outmost object
190
	 *
191
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
192
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
193
	 */
194
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
195
	{
196
		parent::setObject( $object );
197
198
		$this->controller->setObject( $object );
199
200
		return $this;
201
	}
202
203
204
	/**
205
	 * Sets the referenced domains that will be fetched too when retrieving items
206
	 *
207
	 * @param array $domains Domain names of the referenced items that should be fetched too
208
	 * @return \Aimeos\Controller\Frontend\Subscription\Iface Subscription controller for fluent interface
209
	 * @since 2022.04
210
	 */
211
	public function uses( array $domains ) : \Aimeos\Controller\Frontend\Subscription\Iface
212
	{
213
		$this->controller->uses( $domains );
214
		return $this;
215
	}
216
217
218
	/**
219
	 * Returns the frontend controller
220
	 *
221
	 * @return \Aimeos\Controller\Frontend\Iface Frontend controller object
222
	 */
223
	protected function getController() : \Aimeos\Controller\Frontend\Iface
224
	{
225
		return $this->controller;
226
	}
227
}
228