Passed
Push — master ( 0b8510...665276 )
by Aimeos
05:27
created

Standard::getSubManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Plugin
8
 */
9
10
11
namespace Aimeos\MShop\Plugin\Manager;
12
13
14
/**
15
 * Default plugin manager implementation.
16
 *
17
 * @package MShop
18
 * @subpackage Plugin
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Plugin\Manager\Base
22
	implements \Aimeos\MShop\Plugin\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
23
{
24
	private array $searchConfig = array(
25
		'type' => array(
26
			'label' => 'Type ID',
27
			'code' => 'plugin.type',
28
			'internalcode' => 'mplu."type"',
29
		),
30
		'label' => array(
31
			'label' => 'Label',
32
			'code' => 'plugin.label',
33
			'internalcode' => 'mplu."label"',
34
		),
35
		'provider' => array(
36
			'label' => 'Provider',
37
			'code' => 'plugin.provider',
38
			'internalcode' => 'mplu."provider"',
39
		),
40
		'pos' => array(
41
			'label' => 'Position',
42
			'code' => 'plugin.position',
43
			'internalcode' => 'mplu."pos"',
44
			'type' => 'int',
45
		),
46
		'status' => array(
47
			'label' => 'Status',
48
			'code' => 'plugin.status',
49
			'internalcode' => 'mplu."status"',
50
			'type' => 'int',
51
		),
52
		'config' => array(
53
			'label' => 'Configuration',
54
			'code' => 'plugin.config',
55
			'internalcode' => 'mplu."config"',
56
			'type' => 'json',
57
			'public' => false,
58
		),
59
	);
60
61
62
	/**
63
	 * Creates a new empty item instance
64
	 *
65
	 * @param array $values Values the item should be initialized with
66
	 * @return \Aimeos\MShop\Plugin\Item\Iface New plugin item object
67
	 */
68
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
69
	{
70
		$values['plugin.siteid'] = $values['plugin.siteid'] ?? $this->context()->locale()->getSiteId();
71
		return new \Aimeos\MShop\Plugin\Item\Standard( 'plugin.', $values );
72
	}
73
74
75
	/**
76
	 * Creates a filter object.
77
	 *
78
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
79
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
80
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
81
	 */
82
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
83
	{
84
		return $this->filterBase( 'plugin', $default );
85
	}
86
87
88
	/**
89
	 * Returns the additional column/search definitions
90
	 *
91
	 * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
92
	 */
93
	public function getSaveAttributes() : array
94
	{
95
		return $this->createAttributes( $this->searchConfig );
96
	}
97
98
99
	/**
100
	 * Returns the prefix for the item properties and search keys.
101
	 *
102
	 * @return string Prefix for the item properties and search keys
103
	 */
104
	protected function getPrefix() : string
105
	{
106
		return 'plugin.';
107
	}
108
109
110
	/** mshop/plugin/manager/name
111
	 * Class name of the used plugin manager implementation
112
	 *
113
	 * Each default manager can be replace by an alternative imlementation.
114
	 * To use this implementation, you have to set the last part of the class
115
	 * name as configuration value so the manager factory knows which class it
116
	 * has to instantiate.
117
	 *
118
	 * For example, if the name of the default class is
119
	 *
120
	 *  \Aimeos\MShop\Plugin\Manager\Standard
121
	 *
122
	 * and you want to replace it with your own version named
123
	 *
124
	 *  \Aimeos\MShop\Plugin\Manager\Mymanager
125
	 *
126
	 * then you have to set the this configuration option:
127
	 *
128
	 *  mshop/plugin/manager/name = Mymanager
129
	 *
130
	 * The value is the last part of your own class name and it's case sensitive,
131
	 * so take care that the configuration value is exactly named like the last
132
	 * part of the class name.
133
	 *
134
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
135
	 * characters are possible! You should always start the last part of the class
136
	 * name with an upper case character and continue only with lower case characters
137
	 * or numbers. Avoid chamel case names like "MyManager"!
138
	 *
139
	 * @param string Last part of the class name
140
	 * @since 2015.10
141
	 */
142
143
	/** mshop/plugin/manager/decorators/excludes
144
	 * Excludes decorators added by the "common" option from the plugin manager
145
	 *
146
	 * Decorators extend the functionality of a class by adding new aspects
147
	 * (e.g. log what is currently done), executing the methods of the underlying
148
	 * class only in certain conditions (e.g. only for logged in users) or
149
	 * modify what is returned to the caller.
150
	 *
151
	 * This option allows you to remove a decorator added via
152
	 * "mshop/common/manager/decorators/default" before they are wrapped
153
	 * around the plugin manager.
154
	 *
155
	 *  mshop/plugin/manager/decorators/excludes = array( 'decorator1' )
156
	 *
157
	 * This would remove the decorator named "decorator1" from the list of
158
	 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
159
	 * "mshop/common/manager/decorators/default" for the plugin manager.
160
	 *
161
	 * @param array List of decorator names
162
	 * @since 2015.10
163
	 * @see mshop/common/manager/decorators/default
164
	 * @see mshop/plugin/manager/decorators/global
165
	 * @see mshop/plugin/manager/decorators/local
166
	 */
167
168
	/** mshop/plugin/manager/decorators/global
169
	 * Adds a list of globally available decorators only to the plugin manager
170
	 *
171
	 * Decorators extend the functionality of a class by adding new aspects
172
	 * (e.g. log what is currently done), executing the methods of the underlying
173
	 * class only in certain conditions (e.g. only for logged in users) or
174
	 * modify what is returned to the caller.
175
	 *
176
	 * This option allows you to wrap global decorators
177
	 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the plugin manager.
178
	 *
179
	 *  mshop/plugin/manager/decorators/global = array( 'decorator1' )
180
	 *
181
	 * This would add the decorator named "decorator1" defined by
182
	 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the plugin
183
	 * manager.
184
	 *
185
	 * @param array List of decorator names
186
	 * @since 2015.10
187
	 * @see mshop/common/manager/decorators/default
188
	 * @see mshop/plugin/manager/decorators/excludes
189
	 * @see mshop/plugin/manager/decorators/local
190
	 */
191
192
	/** mshop/plugin/manager/decorators/local
193
	 * Adds a list of local decorators only to the plugin manager
194
	 *
195
	 * Decorators extend the functionality of a class by adding new aspects
196
	 * (e.g. log what is currently done), executing the methods of the underlying
197
	 * class only in certain conditions (e.g. only for logged in users) or
198
	 * modify what is returned to the caller.
199
	 *
200
	 * This option allows you to wrap local decorators
201
	 * ("\Aimeos\MShop\Plugin\Manager\Decorator\*") around the plugin manager.
202
	 *
203
	 *  mshop/plugin/manager/decorators/local = array( 'decorator2' )
204
	 *
205
	 * This would add the decorator named "decorator2" defined by
206
	 * "\Aimeos\MShop\Plugin\Manager\Decorator\Decorator2" only to the plugin
207
	 * manager.
208
	 *
209
	 * @param array List of decorator names
210
	 * @since 2015.10
211
	 * @see mshop/common/manager/decorators/default
212
	 * @see mshop/plugin/manager/decorators/excludes
213
	 * @see mshop/plugin/manager/decorators/global
214
	 */
215
216
	/** mshop/plugin/manager/resource
217
	 * Name of the database connection resource to use
218
	 *
219
	 * You can configure a different database connection for each data domain
220
	 * and if no such connection name exists, the "db" connection will be used.
221
	 * It's also possible to use the same database connection for different
222
	 * data domains by configuring the same connection name using this setting.
223
	 *
224
	 * @param string Database connection name
225
	 * @since 2023.04
226
	 */
227
228
229
	/** mshop/plugin/manager/delete/mysql
230
	 * Deletes the items matched by the given IDs from the database
231
	 *
232
	 * @see mshop/plugin/manager/delete/ansi
233
	 */
234
235
	/** mshop/plugin/manager/delete/ansi
236
	 * Deletes the items matched by the given IDs from the database
237
	 *
238
	 * Removes the records specified by the given IDs from the plugin database.
239
	 * The records must be from the site that is configured via the
240
	 * context item.
241
	 *
242
	 * The ":cond" placeholder is replaced by the name of the ID column and
243
	 * the given ID or list of IDs while the site ID is bound to the question
244
	 * mark.
245
	 *
246
	 * The SQL statement should conform to the ANSI standard to be
247
	 * compatible with most relational database systems. This also
248
	 * includes using double quotes for table and column names.
249
	 *
250
	 * @param string SQL statement for deleting items
251
	 * @since 2015.10
252
	 * @see mshop/plugin/manager/insert/ansi
253
	 * @see mshop/plugin/manager/update/ansi
254
	 * @see mshop/plugin/manager/newid/ansi
255
	 * @see mshop/plugin/manager/search/ansi
256
	 * @see mshop/plugin/manager/count/ansi
257
	 */
258
259
	 /** mshop/plugin/manager/submanagers
260
	 * List of manager names that can be instantiated by the plugin manager
261
	 *
262
	 * Managers provide a generic interface to the underlying storage.
263
	 * Each manager has or can have sub-managers caring about particular
264
	 * aspects. Each of these sub-managers can be instantiated by its
265
	 * parent manager using the getSubManager() method.
266
	 *
267
	 * The search keys from sub-managers can be normally used in the
268
	 * manager as well. It allows you to search for items of the manager
269
	 * using the search keys of the sub-managers to further limit the
270
	 * retrieved list of items.
271
	 *
272
	 * @param array List of sub-manager names
273
	 * @since 2015.10
274
	 */
275
276
	 /** mshop/plugin/manager/insert/mysql
277
	 * Inserts a new plugin record into the database table
278
	 *
279
	 * @see mshop/plugin/manager/insert/ansi
280
	 */
281
282
	/** mshop/plugin/manager/insert/ansi
283
	 * Inserts a new plugin record into the database table
284
	 *
285
	 * Items with no ID yet (i.e. the ID is NULL) will be created in
286
	 * the database and the newly created ID retrieved afterwards
287
	 * using the "newid" SQL statement.
288
	 *
289
	 * The SQL statement must be a string suitable for being used as
290
	 * prepared statement. It must include question marks for binding
291
	 * the values from the plugin item to the statement before they are
292
	 * sent to the database server. The number of question marks must
293
	 * be the same as the number of columns listed in the INSERT
294
	 * statement. The catalog of the columns must correspond to the
295
	 * catalog in the save() method, so the correct values are
296
	 * bound to the columns.
297
	 *
298
	 * The SQL statement should conform to the ANSI standard to be
299
	 * compatible with most relational database systems. This also
300
	 * includes using double quotes for table and column names.
301
	 *
302
	 * @param string SQL statement for inserting records
303
	 * @since 2015.10
304
	 * @see mshop/plugin/manager/update/ansi
305
	 * @see mshop/plugin/manager/newid/ansi
306
	 * @see mshop/plugin/manager/delete/ansi
307
	 * @see mshop/plugin/manager/search/ansi
308
	 * @see mshop/plugin/manager/count/ansi
309
	 */
310
311
	 /** mshop/plugin/manager/update/mysql
312
	 * Updates an existing plugin record in the database
313
	 *
314
	 * @see mshop/plugin/manager/update/ansi
315
	 */
316
317
	/** mshop/plugin/manager/update/ansi
318
	 * Updates an existing plugin record in the database
319
	 *
320
	 * Items which already have an ID (i.e. the ID is not NULL) will
321
	 * be updated in the database.
322
	 *
323
	 * The SQL statement must be a string suitable for being used as
324
	 * prepared statement. It must include question marks for binding
325
	 * the values from the plugin item to the statement before they are
326
	 * sent to the database server. The catalog of the columns must
327
	 * correspond to the catalog in the save() method, so the
328
	 * correct values are bound to the columns.
329
	 *
330
	 * The SQL statement should conform to the ANSI standard to be
331
	 * compatible with most relational database systems. This also
332
	 * includes using double quotes for table and column names.
333
	 *
334
	 * @param string SQL statement for updating records
335
	 * @since 2015.10
336
	 * @see mshop/plugin/manager/insert/ansi
337
	 * @see mshop/plugin/manager/newid/ansi
338
	 * @see mshop/plugin/manager/delete/ansi
339
	 * @see mshop/plugin/manager/search/ansi
340
	 * @see mshop/plugin/manager/count/ansi
341
	 */
342
343
	/** mshop/plugin/manager/newid/mysql
344
	 * Retrieves the ID generated by the database when inserting a new record
345
	 *
346
	 * @see mshop/plugin/manager/newid/ansi
347
	 */
348
349
	/** mshop/plugin/manager/newid/ansi
350
	 * Retrieves the ID generated by the database when inserting a new record
351
	 *
352
	 * As soon as a new record is inserted into the database table,
353
	 * the database server generates a new and unique identifier for
354
	 * that record. This ID can be used for retrieving, updating and
355
	 * deleting that specific record from the table again.
356
	 *
357
	 * For MySQL:
358
	 *  SELECT LAST_INSERT_ID()
359
	 * For PostgreSQL:
360
	 *  SELECT currval('seq_mrul_id')
361
	 * For SQL Server:
362
	 *  SELECT SCOPE_IDENTITY()
363
	 * For Oracle:
364
	 *  SELECT "seq_mrul_id".CURRVAL FROM DUAL
365
	 *
366
	 * There's no way to retrive the new ID by a SQL statements that
367
	 * fits for most database servers as they implement their own
368
	 * specific way.
369
	 *
370
	 * @param string SQL statement for retrieving the last inserted record ID
371
	 * @since 2015.10
372
	 * @see mshop/plugin/manager/insert/ansi
373
	 * @see mshop/plugin/manager/update/ansi
374
	 * @see mshop/plugin/manager/delete/ansi
375
	 * @see mshop/plugin/manager/search/ansi
376
	 * @see mshop/plugin/manager/count/ansi
377
	 */
378
379
	/** mshop/plugin/manager/sitemode
380
	 * Mode how items from levels below or above in the site tree are handled
381
	 *
382
	 * By default, only items from the current site are fetched from the
383
	 * storage. If the ai-sites extension is installed, you can create a
384
	 * tree of sites. Then, this setting allows you to define for the
385
	 * whole plugin domain if items from parent sites are inherited,
386
	 * sites from child sites are aggregated or both.
387
	 *
388
	 * Available constants for the site mode are:
389
	 * * 0 = only items from the current site
390
	 * * 1 = inherit items from parent sites
391
	 * * 2 = aggregate items from child sites
392
	 * * 3 = inherit and aggregate items at the same time
393
	 *
394
	 * You also need to set the mode in the locale manager
395
	 * (mshop/locale/manager/sitelevel) to one of the constants.
396
	 * If you set it to the same value, it will work as described but you
397
	 * can also use different modes. For example, if inheritance and
398
	 * aggregation is configured the locale manager but only inheritance
399
	 * in the domain manager because aggregating items makes no sense in
400
	 * this domain, then items wil be only inherited. Thus, you have full
401
	 * control over inheritance and aggregation in each domain.
402
	 *
403
	 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
404
	 * @since 2018.01
405
	 * @see mshop/locale/manager/sitelevel
406
	 */
407
408
	/** mshop/plugin/manager/search/mysql
409
	 * Retrieves the records matched by the given criteria in the database
410
	 *
411
	 * @see mshop/plugin/manager/search/ansi
412
	 */
413
414
	/** mshop/plugin/manager/search/ansi
415
	 * Retrieves the records matched by the given criteria in the database
416
	 *
417
	 * Fetches the records matched by the given criteria from the plugin
418
	 * database. The records must be from one of the sites that are
419
	 * configured via the context item. If the current site is part of
420
	 * a tree of sites, the SELECT statement can retrieve all records
421
	 * from the current site and the complete sub-tree of sites.
422
	 *
423
	 * As the records can normally be limited by criteria from sub-managers,
424
	 * their tables must be joined in the SQL context. This is done by
425
	 * using the "internaldeps" property from the definition of the ID
426
	 * column of the sub-managers. These internal dependencies specify
427
	 * the JOIN between the tables and the used columns for joining. The
428
	 * ":joins" placeholder is then replaced by the JOIN strings from
429
	 * the sub-managers.
430
	 *
431
	 * To limit the records matched, conditions can be added to the given
432
	 * criteria object. It can contain comparisons like column names that
433
	 * must match specific values which can be combined by AND, OR or NOT
434
	 * operators. The resulting string of SQL conditions replaces the
435
	 * ":cond" placeholder before the statement is sent to the database
436
	 * server.
437
	 *
438
	 * If the records that are retrieved should be cataloged by one or more
439
	 * columns, the generated string of column / sort direction pairs
440
	 * replaces the ":catalog" placeholder. In case no cataloging is required,
441
	 * the complete ORDER BY part including the "\/*-catalogby*\/...\/*catalogby-*\/"
442
	 * markers is removed to speed up retrieving the records. Columns of
443
	 * sub-managers can also be used for cataloging the result set but then
444
	 * no index can be used.
445
	 *
446
	 * The number of returned records can be limited and can start at any
447
	 * number between the begining and the end of the result set. For that
448
	 * the ":size" and ":start" placeholders are replaced by the
449
	 * corresponding values from the criteria object. The default values
450
	 * are 0 for the start and 100 for the size value.
451
	 *
452
	 * The SQL statement should conform to the ANSI standard to be
453
	 * compatible with most relational database systems. This also
454
	 * includes using double quotes for table and column names.
455
	 *
456
	 * @param string SQL statement for searching items
457
	 * @since 2015.10
458
	 * @see mshop/plugin/manager/insert/ansi
459
	 * @see mshop/plugin/manager/update/ansi
460
	 * @see mshop/plugin/manager/newid/ansi
461
	 * @see mshop/plugin/manager/delete/ansi
462
	 * @see mshop/plugin/manager/count/ansi
463
	 */
464
465
	/** mshop/plugin/manager/count/mysql
466
	 * Counts the number of records matched by the given criteria in the database
467
	 *
468
	 * @see mshop/plugin/manager/count/ansi
469
	 */
470
471
	/** mshop/plugin/manager/count/ansi
472
	 * Counts the number of records matched by the given criteria in the database
473
	 *
474
	 * Counts all records matched by the given criteria from the plugin
475
	 * database. The records must be from one of the sites that are
476
	 * configured via the context item. If the current site is part of
477
	 * a tree of sites, the statement can count all records from the
478
	 * current site and the complete sub-tree of sites.
479
	 *
480
	 * As the records can normally be limited by criteria from sub-managers,
481
	 * their tables must be joined in the SQL context. This is done by
482
	 * using the "internaldeps" property from the definition of the ID
483
	 * column of the sub-managers. These internal dependencies specify
484
	 * the JOIN between the tables and the used columns for joining. The
485
	 * ":joins" placeholder is then replaced by the JOIN strings from
486
	 * the sub-managers.
487
	 *
488
	 * To limit the records matched, conditions can be added to the given
489
	 * criteria object. It can contain comparisons like column names that
490
	 * must match specific values which can be combined by AND, OR or NOT
491
	 * operators. The resulting string of SQL conditions replaces the
492
	 * ":cond" placeholder before the statement is sent to the database
493
	 * server.
494
	 *
495
	 * Both, the strings for ":joins" and for ":cond" are the same as for
496
	 * the "search" SQL statement.
497
	 *
498
	 * Contrary to the "search" statement, it doesn't return any records
499
	 * but instead the number of records that have been found. As counting
500
	 * thousands of records can be a long running task, the maximum number
501
	 * of counted records is limited for performance reasons.
502
	 *
503
	 * The SQL statement should conform to the ANSI standard to be
504
	 * compatible with most relational database systems. This also
505
	 * includes using double quotes for table and column names.
506
	 *
507
	 * @param string SQL statement for counting items
508
	 * @since 2015.10
509
	 * @see mshop/plugin/manager/insert/ansi
510
	 * @see mshop/plugin/manager/update/ansi
511
	 * @see mshop/plugin/manager/newid/ansi
512
	 * @see mshop/plugin/manager/delete/ansi
513
	 * @see mshop/plugin/manager/search/ansi
514
	 */
515
}
516