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