1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Stock; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Stock frontend controller factory. |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
class Factory |
21
|
|
|
extends \Aimeos\Controller\Frontend\Common\Factory\Base |
22
|
|
|
implements \Aimeos\Controller\Frontend\Common\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Creates a new stock controller object. |
26
|
|
|
* |
27
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context instance with necessary objects |
28
|
|
|
* @param string|null $name Name of the controller implementaton (default: "Standard") |
29
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Controller object |
30
|
|
|
*/ |
31
|
|
|
public static function create( \Aimeos\MShop\Context\Item\Iface $context, $name = null ) |
32
|
|
|
{ |
33
|
|
|
/** controller/frontend/stock/name |
34
|
|
|
* Class name of the used stock frontend controller implementation |
35
|
|
|
* |
36
|
|
|
* Each default frontend controller can be replace by an alternative imlementation. |
37
|
|
|
* To use this implementation, you have to set the last part of the class |
38
|
|
|
* name as configuration value so the controller factory knows which class it |
39
|
|
|
* has to instantiate. |
40
|
|
|
* |
41
|
|
|
* For example, if the name of the default class is |
42
|
|
|
* |
43
|
|
|
* \Aimeos\Controller\Frontend\Stock\Standard |
44
|
|
|
* |
45
|
|
|
* and you want to replace it with your own version named |
46
|
|
|
* |
47
|
|
|
* \Aimeos\Controller\Frontend\Stock\Mystock |
48
|
|
|
* |
49
|
|
|
* then you have to set the this configuration option: |
50
|
|
|
* |
51
|
|
|
* controller/jobs/frontend/stock/name = Mystock |
52
|
|
|
* |
53
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
54
|
|
|
* so take care that the configuration value is exactly named like the last |
55
|
|
|
* part of the class name. |
56
|
|
|
* |
57
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
58
|
|
|
* characters are possible! You should always start the last part of the class |
59
|
|
|
* name with an upper case character and continue only with lower case characters |
60
|
|
|
* or numbers. Avoid chamel case names like "MyStock"! |
61
|
|
|
* |
62
|
|
|
* @param string Last part of the class name |
63
|
|
|
* @since 2017.03 |
64
|
|
|
* @category Developer |
65
|
|
|
*/ |
66
|
|
|
if( $name === null ) { |
67
|
|
|
$name = $context->getConfig()->get( 'controller/frontend/stock/name', 'Standard' ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if( ctype_alnum( $name ) === false ) |
71
|
|
|
{ |
72
|
|
|
$classname = is_string( $name ) ? '\\Aimeos\\Controller\\Frontend\\Stock\\' . $name : '<not a string>'; |
73
|
|
|
throw new \Aimeos\Controller\Frontend\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$iface = '\\Aimeos\\Controller\\Frontend\\Stock\\Iface'; |
77
|
|
|
$classname = '\\Aimeos\\Controller\\Frontend\\Stock\\' . $name; |
78
|
|
|
|
79
|
|
|
$manager = self::createController( $context, $classname, $iface ); |
80
|
|
|
|
81
|
|
|
/** controller/frontend/stock/decorators/excludes |
82
|
|
|
* Excludes decorators added by the "common" option from the stock frontend controllers |
83
|
|
|
* |
84
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
85
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
86
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
87
|
|
|
* modify what is returned to the caller. |
88
|
|
|
* |
89
|
|
|
* This option allows you to remove a decorator added via |
90
|
|
|
* "controller/frontend/common/decorators/default" before they are wrapped |
91
|
|
|
* around the frontend controller. |
92
|
|
|
* |
93
|
|
|
* controller/frontend/stock/decorators/excludes = array( 'decorator1' ) |
94
|
|
|
* |
95
|
|
|
* This would remove the decorator named "decorator1" from the list of |
96
|
|
|
* common decorators ("\Aimeos\Controller\Frontend\Common\Decorator\*") added via |
97
|
|
|
* "controller/frontend/common/decorators/default" for the stock frontend controller. |
98
|
|
|
* |
99
|
|
|
* @param array List of decorator names |
100
|
|
|
* @since 2017.03 |
101
|
|
|
* @category Developers |
102
|
|
|
* @see controller/frontend/common/decorators/default |
103
|
|
|
* @see controller/frontend/stock/decorators/global |
104
|
|
|
* @see controller/frontend/stock/decorators/local |
105
|
|
|
*/ |
106
|
|
|
|
107
|
|
|
/** controller/frontend/stock/decorators/global |
108
|
|
|
* Adds a list of globally available decorators only to the stock frontend controllers |
109
|
|
|
* |
110
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
111
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
112
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
113
|
|
|
* modify what is returned to the caller. |
114
|
|
|
* |
115
|
|
|
* This option allows you to wrap global decorators |
116
|
|
|
* ("\Aimeos\Controller\Frontend\Common\Decorator\*") around the frontend controller. |
117
|
|
|
* |
118
|
|
|
* controller/frontend/stock/decorators/global = array( 'decorator1' ) |
119
|
|
|
* |
120
|
|
|
* This would add the decorator named "decorator1" defined by |
121
|
|
|
* "\Aimeos\Controller\Frontend\Common\Decorator\Decorator1" only to the frontend controller. |
122
|
|
|
* |
123
|
|
|
* @param array List of decorator names |
124
|
|
|
* @since 2017.03 |
125
|
|
|
* @category Developers |
126
|
|
|
* @see controller/frontend/common/decorators/default |
127
|
|
|
* @see controller/frontend/stock/decorators/excludes |
128
|
|
|
* @see controller/frontend/stock/decorators/local |
129
|
|
|
*/ |
130
|
|
|
|
131
|
|
|
/** controller/frontend/stock/decorators/local |
132
|
|
|
* Adds a list of local decorators only to the stock frontend controllers |
133
|
|
|
* |
134
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
135
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
136
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
137
|
|
|
* modify what is returned to the caller. |
138
|
|
|
* |
139
|
|
|
* This option allows you to wrap local decorators |
140
|
|
|
* ("\Aimeos\Controller\Frontend\Stock\Decorator\*") around the frontend controller. |
141
|
|
|
* |
142
|
|
|
* controller/frontend/stock/decorators/local = array( 'decorator2' ) |
143
|
|
|
* |
144
|
|
|
* This would add the decorator named "decorator2" defined by |
145
|
|
|
* "\Aimeos\Controller\Frontend\Stock\Decorator\Decorator2" only to the frontend |
146
|
|
|
* controller. |
147
|
|
|
* |
148
|
|
|
* @param array List of decorator names |
149
|
|
|
* @since 2017.03 |
150
|
|
|
* @category Developers |
151
|
|
|
* @see controller/frontend/common/decorators/default |
152
|
|
|
* @see controller/frontend/stock/decorators/excludes |
153
|
|
|
* @see controller/frontend/stock/decorators/global |
154
|
|
|
*/ |
155
|
|
|
return self::addControllerDecorators( $context, $manager, 'stock' ); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|