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-2023 |
7
|
|
|
* @package MAdmin |
8
|
|
|
* @subpackage Common |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MAdmin\Common\Manager; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Provides common methods required by most of the manager classes. |
17
|
|
|
* |
18
|
|
|
* @package MAdmin |
19
|
|
|
* @subpackage Common |
20
|
|
|
*/ |
21
|
|
|
abstract class Base extends \Aimeos\MShop\Common\Manager\Base |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Adds the configured decorators to the given manager object. |
25
|
|
|
* |
26
|
|
|
* @param \Aimeos\MShop\Common\Manager\Iface $manager Manager object |
27
|
|
|
* @param string $managerpath Manager sub-names separated by slashes, e.g. "lists/type" |
28
|
|
|
* @param string $domain Domain name in lower case, e.g. "product" |
29
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager with decorators added |
30
|
|
|
*/ |
31
|
|
|
protected function addManagerDecorators( \Aimeos\MShop\Common\Manager\Iface $manager, string $managerpath, string $domain ) : \Aimeos\MShop\Common\Manager\Iface |
32
|
|
|
{ |
33
|
|
|
$context = $this->context(); |
34
|
|
|
$config = $context->config(); |
35
|
|
|
|
36
|
|
|
/** madmin/common/manager/decorators/default |
37
|
|
|
* Configures the list of decorators applied to all admin managers |
38
|
|
|
* |
39
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
40
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
41
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
42
|
|
|
* modify what is returned to the caller. |
43
|
|
|
* |
44
|
|
|
* This option allows you to configure a list of decorator names that should |
45
|
|
|
* be wrapped around the original instances of all created managers: |
46
|
|
|
* |
47
|
|
|
* madmin/common/manager/decorators/default = array( 'decorator1', 'decorator2' ) |
48
|
|
|
* |
49
|
|
|
* This would wrap the decorators named "decorator1" and "decorator2" around |
50
|
|
|
* all controller instances in that order. The decorator classes would be |
51
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" and |
52
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator2". |
53
|
|
|
* |
54
|
|
|
* @param array List of decorator names |
55
|
|
|
* @since 2014.03 |
56
|
|
|
* @category Developer |
57
|
|
|
*/ |
58
|
|
|
$decorators = $config->get( 'madmin/common/manager/decorators/default', [] ); |
59
|
|
|
$excludes = $config->get( 'madmin/' . $domain . '/manager/' . $managerpath . '/decorators/excludes', [] ); |
60
|
|
|
|
61
|
|
|
foreach( $decorators as $key => $name ) |
62
|
|
|
{ |
63
|
|
|
if( in_array( $name, $excludes ) ) { |
64
|
|
|
unset( $decorators[$key] ); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$classprefix = '\Aimeos\MShop\Common\Manager\Decorator\\'; |
69
|
|
|
$manager = $this->addDecorators( $context, $manager, $decorators, $classprefix ); |
70
|
|
|
|
71
|
|
|
$classprefix = '\Aimeos\MShop\Common\Manager\Decorator\\'; |
72
|
|
|
$decorators = $config->get( 'madmin/' . $domain . '/manager/' . $managerpath . '/decorators/global', [] ); |
73
|
|
|
$manager = $this->addDecorators( $context, $manager, $decorators, $classprefix ); |
74
|
|
|
|
75
|
|
|
$subpath = $this->createSubNames( $managerpath ); |
76
|
|
|
$classprefix = 'MShop_' . ucfirst( $domain ) . '_Manager_' . $subpath . '_Decorator_'; |
77
|
|
|
$decorators = $config->get( 'madmin/' . $domain . '/manager/' . $managerpath . '/decorators/local', [] ); |
78
|
|
|
|
79
|
|
|
return $this->addDecorators( $context, $manager, $decorators, $classprefix ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns a new manager the given extension name |
85
|
|
|
* |
86
|
|
|
* @param string $domain Name of the domain (product, text, media, etc.) |
87
|
|
|
* @param string $manager Name of the sub manager type in lower case (can contain a path like base/product) |
88
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
89
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions |
90
|
|
|
* @throws \LogicException If class isn't found |
91
|
|
|
*/ |
92
|
|
|
protected function getSubManagerBase( string $domain, string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface |
93
|
|
|
{ |
94
|
|
|
$context = $this->context(); |
95
|
|
|
$domain = strtolower( $domain ); |
96
|
|
|
$manager = strtolower( $manager ); |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
if( empty( $domain ) || ctype_alnum( $domain ) === false ) { |
100
|
|
|
throw new \LogicException( sprintf( 'Invalid characters in domain name "%1$s"', $domain ), 400 ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if( $name === null ) { |
104
|
|
|
$name = $context->config()->get( 'mshop/' . $domain . '/manager/' . $manager . '/name', 'Standard' ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if( empty( $name ) || ctype_alnum( $name ) === false ) { |
108
|
|
|
throw new \LogicException( sprintf( 'Invalid characters in manager name "%1$s"', $name ), 400 ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$domainname = ucfirst( $domain ); |
112
|
|
|
$subnames = $this->createSubNames( $manager ); |
113
|
|
|
|
114
|
|
|
$classname = '\Aimeos\MAdmin\\' . $domainname . '\Manager\\' . $subnames . '\\' . $name; |
115
|
|
|
$interface = '\Aimeos\MAdmin\\' . $domainname . '\Manager\\' . $subnames . '\Iface'; |
116
|
|
|
|
117
|
|
|
return \Aimeos\Utils::create( $classname, [$context], $interface ); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|