1 | <?php |
||
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 |