Passed
Push — master ( e78dfc...695473 )
by Aimeos
04:21
created

Base::classes()   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, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 * @package MShop
8
 * @subpackage Common
9
 */
10
11
12
namespace Aimeos\MShop\Common\Manager\Decorator;
13
14
15
/**
16
 * Provides common methods for manager decorators.
17
 *
18
 * @package MShop
19
 * @subpackage Common
20
 */
21
abstract class Base
22
	extends \Aimeos\MShop\Common\Manager\Base
23
	implements \Aimeos\MShop\Common\Manager\Decorator\Iface
24
{
25
	private $manager;
26
27
28
	/**
29
	 * Initializes the manager decorator.
30
	 *
31
	 * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager object
32
	 * @param \Aimeos\MShop\ContextIface $context Context object with required objects
33
	 */
34
	public function __construct( \Aimeos\MShop\Common\Manager\Iface $manager, \Aimeos\MShop\ContextIface $context )
35
	{
36
		parent::__construct( $context );
37
		$this->manager = $manager;
38
	}
39
40
41
	/**
42
	 * Passes unknown methods to wrapped objects.
43
	 *
44
	 * @param string $name Name of the method
45
	 * @param array $param List of method parameter
46
	 * @return mixed Returns the value of the called method
47
	 * @throws \Aimeos\MShop\Exception If method call failed
48
	 */
49
	public function __call( string $name, array $param )
50
	{
51
		return call_user_func_array( array( $this->manager, $name ), $param );
52
	}
53
54
55
	/**
56
	 * Adds a filter callback for an item type
57
	 *
58
	 * @param string $iface Interface name of the item to apply the filter to
59
	 * @param \Closure $fcn Anonymous function receiving the item to check as first parameter
60
	 */
61
	public function addFilter( string $iface, \Closure $fcn )
62
	{
63
		$this->manager->addFilter( $iface, $fcn );
64
	}
65
66
67
	/**
68
	 * Returns the class names of the manager and used decorators.
69
	 *
70
	 * @return array List of class names
71
	 */
72
	public function classes() : array
73
	{
74
		return array_merge( $this->getManager()->classes(), [get_class( $this )] );
75
	}
76
77
78
	/**
79
	 * Removes old entries from the storage
80
	 *
81
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
82
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
83
	 */
84
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
85
	{
86
		$this->manager->clear( $siteids );
87
		return $this;
88
	}
89
90
91
	/**
92
	 * Creates a new empty item instance
93
	 *
94
	 * @param array $values Values the item should be initialized with
95
	 * @return \Aimeos\MShop\Common\Item\Iface New item object
96
	 */
97
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
98
	{
99
		return $this->manager->create( $values );
100
	}
101
102
103
	/**
104
	 * Deletes one or more items.
105
	 *
106
	 * @param \Aimeos\MShop\Common\Item\Iface|array|string $items Item object, ID of the item or a list of them
107
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
108
	 */
109
	public function delete( $items ) : \Aimeos\MShop\Common\Manager\Iface
110
	{
111
		$this->manager->delete( $items );
112
		return $this;
113
	}
114
115
116
	/**
117
	 * Creates a filter object.
118
	 *
119
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
120
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
121
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
122
	 */
123
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
124
	{
125
		return $this->manager->filter( $default, $site );
126
	}
127
128
129
	/**
130
	 * Returns the item specified by its ID
131
	 *
132
	 * @param string $id Id of item
133
	 * @param string[] $ref List of domains to fetch list items and referenced items for
134
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
135
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
136
	 */
137
	public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
138
	{
139
		return $this->manager->get( $id, $ref, $default );
140
	}
141
142
143
	/**
144
	 * Returns the available manager types
145
	 *
146
	 * @param bool $withsub Return also the resource type of sub-managers if true
147
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
148
	 */
149
	public function getResourceType( bool $withsub = true ): array
150
	{
151
		return $this->manager->getResourceType( $withsub );
152
	}
153
154
155
	/**
156
	 * Returns the additional column/search definitions
157
	 *
158
	 * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
159
	 */
160
	public function getSaveAttributes() : array
161
	{
162
		return $this->manager->getSaveAttributes();
163
	}
164
165
166
	/**
167
	 * Returns the attributes that can be used for searching.
168
	 *
169
	 * @param bool $withsub Return also attributes of sub-managers if true
170
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items
171
	 */
172
	public function getSearchAttributes( bool $withsub = true ) : array
173
	{
174
		return $this->manager->getSearchAttributes( $withsub );
175
	}
176
177
178
	/**
179
	 * Creates a new extension manager in the domain.
180
	 *
181
	 * @param string $domain Name of the domain (product, text, media, etc.)
182
	 * @param string|null $name Name of the implementation, will be from configuration (or Standard) if null
183
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager extending the domain functionality
184
	 */
185
	public function getSubManager( string $domain, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
186
	{
187
		return $this->manager->getSubManager( $domain, $name );
188
	}
189
190
191
	/**
192
	 * Adds or updates an item object or a list of them.
193
	 *
194
	 * @param \Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface $items Item or list of items whose data should be saved
195
	 * @param bool $fetch True if the new ID should be returned in the item
196
	 * @return \Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface Saved item or items
197
	 */
198
	public function save( $items, bool $fetch = true )
199
	{
200
		return $this->manager->save( $items, $fetch );
201
	}
202
203
204
	/**
205
	 * Searches for all items matching the given critera.
206
	 *
207
	 * @param \Aimeos\Base\Criteria\Iface $filter Criteria object with conditions, sortations, etc.
208
	 * @param string[] $ref List of domains to fetch list items and referenced items for
209
	 * @param int &$total Number of items that are available in total
210
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
211
	 */
212
	public function search( \Aimeos\Base\Criteria\Iface $filter, array $ref = [], int &$total = null ) : \Aimeos\Map
213
	{
214
		return $this->manager->search( $filter, $ref, $total );
215
	}
216
217
218
	/**
219
	 * Injects the reference of the outmost object
220
	 *
221
	 * @param \Aimeos\MShop\Common\Manager\Iface $object Reference to the outmost manager or decorator
222
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
223
	 */
224
	public function setObject( \Aimeos\MShop\Common\Manager\Iface $object ) : \Aimeos\MShop\Common\Manager\Iface
225
	{
226
		parent::setObject( $object );
227
228
		$this->manager->setObject( $object );
229
230
		return $this;
231
	}
232
233
234
	/**
235
	 * Starts a database transaction on the connection identified by the given name
236
	 *
237
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
238
	 */
239
	public function begin() : \Aimeos\MShop\Common\Manager\Iface
240
	{
241
		$this->manager->begin();
242
		return $this;
243
	}
244
245
246
	/**
247
	 * Commits the running database transaction on the connection identified by the given name
248
	 *
249
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
250
	 */
251
	public function commit() : \Aimeos\MShop\Common\Manager\Iface
252
	{
253
		$this->manager->commit();
254
		return $this;
255
	}
256
257
258
	/**
259
	 * Rolls back the running database transaction on the connection identified by the given name
260
	 *
261
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
262
	 */
263
	public function rollback() : \Aimeos\MShop\Common\Manager\Iface
264
	{
265
		$this->manager->rollback();
266
		return $this;
267
	}
268
269
270
271
	/**
272
	 * Returns the manager object
273
	 *
274
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object
275
	 */
276
	protected function getManager() : \Aimeos\MShop\Common\Manager\Iface
277
	{
278
		return $this->manager;
279
	}
280
}
281