1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* zf2-featureflags. |
4
|
|
|
* |
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
11
|
|
|
* SOFTWARE. |
12
|
|
|
* |
13
|
|
|
* @copyright 2016 MehrAlsNix (http://www.mehralsnix.de) |
14
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
15
|
|
|
* |
16
|
|
|
* @link http://github.com/MehrAlsNix/zf2-featureflags |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace MehrAlsNix\FeatureToggle; |
20
|
|
|
|
21
|
|
|
use Qandidate\Toggle\Serializer\InMemoryCollectionSerializer; |
22
|
|
|
use Qandidate\Toggle\ToggleCollection; |
23
|
|
|
use Qandidate\Toggle\ToggleCollection\InMemoryCollection; |
24
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
25
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
26
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
27
|
|
|
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface; |
28
|
|
|
use Zend\ModuleManager\Feature\ControllerPluginProviderInterface; |
29
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
30
|
|
|
use Zend\ModuleManager\Feature\ServiceProviderInterface; |
31
|
|
|
use Zend\ModuleManager\Feature\ViewHelperProviderInterface; |
32
|
|
|
use Zend\ModuleManager\ModuleEvent; |
33
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class Module |
37
|
|
|
* |
38
|
|
|
* @package MehrAlsNix\FeatureToggle |
39
|
|
|
*/ |
40
|
|
|
class Module implements ConfigProviderInterface, |
41
|
|
|
AutoloaderProviderInterface, |
42
|
|
|
ServiceProviderInterface, |
43
|
|
|
ViewHelperProviderInterface, |
44
|
|
|
ControllerPluginProviderInterface, |
45
|
|
|
// InitProviderInterface, |
46
|
|
|
ConsoleUsageProviderInterface |
47
|
|
|
{ |
48
|
|
|
/** |
49
|
|
|
* @param ModuleManagerInterface $moduleManager |
50
|
|
|
/ |
51
|
|
|
public function init(ModuleManagerInterface $moduleManager) |
52
|
|
|
{ |
53
|
|
|
$eventManager = $moduleManager->getEventManager(); |
54
|
|
|
$eventManager->attach(ModuleEvent::EVENT_MERGE_CONFIG, [$this, 'onMergeConfig']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param ModuleEvent $event |
59
|
|
|
/ |
60
|
|
|
public function onMergeConfig(ModuleEvent $event) |
61
|
|
|
{ |
62
|
|
|
$config = $event->getConfigListener()->getMergedConfig(false); |
63
|
|
|
|
64
|
|
|
$event-> |
65
|
|
|
$serializer = new InMemoryCollectionSerializer(); |
66
|
|
|
$collection = $serializer->deserialize($data); |
67
|
|
|
$manager = new ToggleManager($collection); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Retrieve autoloader configuration |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function getAutoloaderConfig() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
'Zend\Loader\StandardAutoloader' => [ |
79
|
|
|
'namespaces' => [ |
80
|
|
|
__NAMESPACE__ => __DIR__ . '/src/', |
81
|
|
|
] |
82
|
|
|
] |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Retrieve module configuration |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getConfig() |
92
|
|
|
{ |
93
|
|
|
return include __DIR__ . '/config/module.config.php'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Expected to return \Zend\ServiceManager\Config object or array to |
98
|
|
|
* seed such an object. |
99
|
|
|
* |
100
|
|
|
* @return array|\Zend\ServiceManager\Config |
101
|
|
|
*/ |
102
|
|
|
public function getServiceConfig() |
103
|
|
|
{ |
104
|
|
|
return [ |
105
|
|
|
'service_manager' => [ |
106
|
|
|
'aliases' => [ |
107
|
|
|
'FeatureToggle\InMemory' => 'Qandidate\Toggle\Collection\InMemory', |
108
|
|
|
'FeatureToggle\Redis' => 'Qandidate\Toggle\Collection\Predis' |
109
|
|
|
], |
110
|
|
|
'services' => [ |
111
|
|
|
'Qandidate\Toggle\Collection\InMemory' => new InMemoryCollection(), |
112
|
|
|
'Qandidate\Toggle\Serializer\InMemoryCollectionSerializer' => new InMemoryCollectionSerializer(), |
113
|
|
|
], |
114
|
|
|
'factories' => [ |
115
|
|
|
'FeatureToggle\UserContextFactory' => Factory\UserContextFactory::class, |
116
|
|
|
'Qandidate\Toggle\Manager' => Factory\ToggleManagerFactory::class, |
117
|
|
|
'Qandidate\Toggle\Context' => Factory\ToggleContextFactory::class |
118
|
|
|
] |
119
|
|
|
] |
120
|
|
|
]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Expected to return \Zend\ServiceManager\Config object or array to |
125
|
|
|
* seed such an object. |
126
|
|
|
* |
127
|
|
|
* @return array|\Zend\ServiceManager\Config |
128
|
|
|
*/ |
129
|
|
|
public function getViewHelperConfig() |
130
|
|
|
{ |
131
|
|
|
return [ |
132
|
|
|
'view_helpers' => [ |
133
|
|
|
'factories' => [ |
134
|
|
|
'FeatureToggle' => Factory\ToggleHelperFactory::class |
135
|
|
|
] |
136
|
|
|
] |
137
|
|
|
]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Expected to return \Zend\ServiceManager\Config object or array to |
142
|
|
|
* seed such an object. |
143
|
|
|
* |
144
|
|
|
* @return array|\Zend\ServiceManager\Config |
145
|
|
|
*/ |
146
|
|
|
public function getControllerPluginConfig() |
147
|
|
|
{ |
148
|
|
|
return [ |
149
|
|
|
'controller_plugins' => [ |
150
|
|
|
'factories' => [ |
151
|
|
|
'FeatureToggle' => Factory\TogglePluginFactory::class |
152
|
|
|
] |
153
|
|
|
] |
154
|
|
|
]; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Returns an array or a string containing usage information for this module's Console commands. |
159
|
|
|
* The method is called with active Zend\Console\Adapter\AdapterInterface that can be used to directly access |
160
|
|
|
* Console and send output. |
161
|
|
|
* |
162
|
|
|
* If the result is a string it will be shown directly in the console window. |
163
|
|
|
* If the result is an array, its contents will be formatted to console window width. The array must |
164
|
|
|
* have the following format: |
165
|
|
|
* |
166
|
|
|
* return array( |
167
|
|
|
* 'Usage information line that should be shown as-is', |
168
|
|
|
* 'Another line of usage info', |
169
|
|
|
* |
170
|
|
|
* '--parameter' => 'A short description of that parameter', |
171
|
|
|
* '-another-parameter' => 'A short description of another parameter', |
172
|
|
|
* ... |
173
|
|
|
* ) |
174
|
|
|
* |
175
|
|
|
* @param AdapterInterface $console |
176
|
|
|
* @return array|string|null |
177
|
|
|
*/ |
178
|
|
|
public function getConsoleUsage(AdapterInterface $console) |
179
|
|
|
{ |
180
|
|
|
return array( |
181
|
|
|
'config dump' => 'Compiles config and dump into cache file.', |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|