1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace PlaygroundCore; |
4
|
|
|
|
5
|
|
|
use Zend\Session\SessionManager; |
6
|
|
|
use Zend\Session\Config\SessionConfig; |
7
|
|
|
use Zend\Session\Container; |
8
|
|
|
use Zend\Validator\AbstractValidator; |
9
|
|
|
use Zend\EventManager\EventInterface; |
10
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
11
|
|
|
use Zend\ModuleManager\Feature\BootstrapListenerInterface; |
12
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
13
|
|
|
use Zend\ModuleManager\Feature\ServiceProviderInterface; |
14
|
|
|
use Zend\ModuleManager\Feature\ViewHelperProviderInterface; |
15
|
|
|
use Zend\ModuleManager\ModuleManager; |
16
|
|
|
use Zend\Uri\UriFactory; |
17
|
|
|
|
18
|
|
|
class Module implements |
|
|
|
|
19
|
|
|
AutoloaderProviderInterface, |
20
|
|
|
BootstrapListenerInterface, |
21
|
|
|
ConfigProviderInterface, |
22
|
|
|
ServiceProviderInterface, |
23
|
|
|
ViewHelperProviderInterface |
24
|
|
|
{ |
25
|
|
|
public function init(ModuleManager $manager) |
26
|
|
|
{ |
27
|
|
|
$eventManager = $manager->getEventManager(); |
28
|
|
|
|
29
|
|
|
/* |
30
|
|
|
* This event change the config before it's cached |
31
|
|
|
* The change will apply to 'template_path_stack' and 'assetic_configuration' |
32
|
|
|
* These 2 config take part in the Playground Theme Management |
33
|
|
|
*/ |
34
|
|
|
$eventManager->attach(\Zend\ModuleManager\ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'), 100); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* This method is called only when the config is not cached. |
39
|
|
|
* @param \Zend\ModuleManager\ModuleEvent $e |
40
|
|
|
*/ |
41
|
|
|
public function onMergeConfig(\Zend\ModuleManager\ModuleEvent $e) |
42
|
|
|
{ |
43
|
|
|
$config = $e->getConfigListener()->getMergedConfig(false); |
44
|
|
|
|
45
|
|
|
if (isset($config['playgroundLocale']) && isset($config['playgroundLocale']['enable']) && $config['playgroundLocale']['enable']) { |
46
|
|
|
$config['router']['routes']['frontend']['options']['route'] = '/[:locale[/]]'; |
47
|
|
|
$config['router']['routes']['frontend']['options']['constraints']['locale'] = '[a-z]{2}([-_][A-Z]{2})?(?=/|$)'; |
48
|
|
|
$config['router']['routes']['frontend']['options']['defaults']['locale'] = $config['playgroundLocale']['default']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$e->getConfigListener()->setMergedConfig($config); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function onBootstrap(EventInterface $e) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
// this is useful for zfr-cors to accept chrome extension like Postman |
57
|
|
|
UriFactory::registerScheme('chrome-extension', 'Zend\Uri\Uri'); |
58
|
|
|
|
59
|
|
|
$serviceManager = $e->getApplication()->getServiceManager(); |
|
|
|
|
60
|
|
|
$config = $e->getApplication()->getServiceManager()->get('config'); |
|
|
|
|
61
|
|
|
|
62
|
|
|
// Locale management |
63
|
|
|
$translator = $serviceManager->get('translator'); |
64
|
|
|
$defaultLocale = 'fr'; |
65
|
|
|
|
66
|
|
|
// Gestion de la locale |
67
|
|
|
if (PHP_SAPI !== 'cli') { |
68
|
|
|
$config = $e->getApplication()->getServiceManager()->get('config'); |
|
|
|
|
69
|
|
|
if (isset($config['playgroundLocale'])) { |
70
|
|
|
$pgLocale = $config['playgroundLocale']; |
71
|
|
|
$defaultLocale = $pgLocale['default']; |
72
|
|
|
|
73
|
|
|
if (isset($pgLocale['strategies'])) { |
74
|
|
|
$pgstrat = $pgLocale['strategies']; |
75
|
|
|
|
76
|
|
|
// Is there a locale in the URL ? |
77
|
|
|
if (in_array('uri', $pgstrat)) { |
78
|
|
|
$path = $e->getRequest()->getUri()->getPath(); |
|
|
|
|
79
|
|
|
$parts = explode('/', trim($path, '/')); |
80
|
|
|
$localeCandidate = array_shift($parts); |
81
|
|
|
// I switch from locale to... language |
82
|
|
|
$localeCandidate = substr($localeCandidate, 0, 2); |
83
|
|
|
|
84
|
|
|
if (in_array($localeCandidate, $pgLocale['supported'])) { |
85
|
|
|
$locale = $localeCandidate; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// Is there a cookie for the locale ? |
90
|
|
|
if (empty($locale) && in_array('cookie', $pgstrat)) { |
91
|
|
|
$serviceManager->get('router')->setTranslator($translator); |
92
|
|
|
if ($serviceManager->get('router')->match($serviceManager->get('request')) && |
93
|
|
|
strpos($serviceManager->get('router')->match($serviceManager->get('request'))->getMatchedRouteName(), 'admin') !==false |
94
|
|
|
) { |
95
|
|
View Code Duplication |
if ($e->getRequest()->getCookie() && |
|
|
|
|
96
|
|
|
$e->getRequest()->getCookie()->offsetExists('pg_locale_back') |
|
|
|
|
97
|
|
|
) { |
98
|
|
|
$locale = $e->getRequest()->getCookie()->offsetGet('pg_locale_back'); |
|
|
|
|
99
|
|
|
} |
100
|
|
View Code Duplication |
} else { |
|
|
|
|
101
|
|
|
if ($e->getRequest()->getCookie() && |
|
|
|
|
102
|
|
|
$e->getRequest()->getCookie()->offsetExists('pg_locale_frontend') |
|
|
|
|
103
|
|
|
) { |
104
|
|
|
$locale = $e->getRequest()->getCookie()->offsetGet('pg_locale_frontend'); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// Is there a locale in the request Header ? |
110
|
|
|
if (empty($locale) && in_array('header', $pgstrat)) { |
111
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
112
|
|
|
$localeCandidate = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); |
113
|
|
|
// I switch from locale to... language |
114
|
|
|
$localeCandidate = substr($localeCandidate, 0, 2); |
115
|
|
|
if (in_array($localeCandidate, $pgLocale['supported'])) { |
116
|
|
|
$locale = $localeCandidate; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
// I take the default locale |
122
|
|
|
if (empty($locale)) { |
123
|
|
|
$locale = $defaultLocale; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// I take the default locale |
128
|
|
|
if (empty($locale)) { |
129
|
|
|
$locale = $defaultLocale; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$translator->setLocale($locale); |
133
|
|
|
|
134
|
|
|
// Attach the translator to the router |
135
|
|
|
$e->getRouter()->setTranslator($translator); |
|
|
|
|
136
|
|
|
$e->getRouter()->setTranslatorTextDomain('routes'); |
|
|
|
|
137
|
|
|
|
138
|
|
|
// Attach the translator to the plugins |
139
|
|
|
$translate = $serviceManager->get('viewhelpermanager')->get('translate'); |
140
|
|
|
$translate->getTranslator()->setLocale($locale); |
141
|
|
|
|
142
|
|
|
$options = $serviceManager->get('playgroundcore_module_options'); |
143
|
|
|
$options->setLocale($locale); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// positionnement de la langue pour les traductions de date avec strftime |
147
|
|
|
setlocale(LC_TIME, "fr_FR", 'fr_FR.utf8', 'fra'); |
148
|
|
|
|
149
|
|
|
AbstractValidator::setDefaultTranslator($translator, 'playgroundcore'); |
150
|
|
|
|
151
|
|
|
/* |
152
|
|
|
* Entity translation based on Doctrine Gedmo library |
153
|
|
|
*/ |
154
|
|
|
$doctrine = $serviceManager->get('doctrine.entitymanager.orm_default'); |
155
|
|
|
$evm = $doctrine->getEventManager(); |
156
|
|
|
|
157
|
|
|
$translatableListener = new \Gedmo\Translatable\TranslatableListener(); |
158
|
|
|
$translatableListener->setDefaultLocale($defaultLocale); |
159
|
|
|
|
160
|
|
|
// If no translation is found, fallback to entity data |
161
|
|
|
$translatableListener->setTranslationFallback(true); |
162
|
|
|
|
163
|
|
|
// set Locale |
164
|
|
|
if (!empty($locale)) { |
165
|
|
|
$translatableListener->setTranslatableLocale($locale); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$evm->addEventSubscriber($translatableListener); |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Adding a Filter to slugify a string (make it URL compliiant) |
172
|
|
|
*/ |
173
|
|
|
$filterChain = new \Zend\Filter\FilterChain(); |
174
|
|
|
$filterChain->getPluginManager()->setInvokableClass( |
175
|
|
|
'slugify', |
176
|
|
|
'PlaygroundCore\Filter\Slugify' |
177
|
|
|
); |
178
|
|
|
$filterChain->attach(new Filter\Slugify()); |
179
|
|
|
|
180
|
|
|
// Start the session container |
181
|
|
|
$sessionConfig = new SessionConfig(); |
182
|
|
|
$sessionConfig->setOptions($config['session']); |
183
|
|
|
$sessionManager = new SessionManager($sessionConfig); |
184
|
|
|
$sessionManager->start(); |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Optional: If you later want to use namespaces, you can already store the |
188
|
|
|
* Manager in the shared (static) Container (=namespace) field |
189
|
|
|
*/ |
190
|
|
|
\Zend\Session\Container::setDefaultManager($sessionManager); |
191
|
|
|
|
192
|
|
|
// Google Analytics : When the render event is triggered, we invoke the view helper to |
193
|
|
|
// render the javascript code. |
194
|
|
|
$e->getApplication()->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function (\Zend\Mvc\MvcEvent $e) use ($serviceManager) { |
|
|
|
|
195
|
|
|
$view = $serviceManager->get('ViewHelperManager'); |
196
|
|
|
$plugin = $view->get('googleAnalytics'); |
197
|
|
|
$plugin(); |
198
|
|
|
|
199
|
|
|
$pluginOG = $view->get('facebookOpengraph'); |
200
|
|
|
$pluginOG(); |
201
|
|
|
|
202
|
|
|
$pluginTC = $view->get('twitterCard'); |
203
|
|
|
$pluginTC(); |
204
|
|
|
}); |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
if (PHP_SAPI !== 'cli') { |
208
|
|
|
$session = new Container('facebook'); |
209
|
|
|
$fb = $e->getRequest()->getPost()->get('signed_request'); |
|
|
|
|
210
|
|
|
if ($fb) { |
211
|
|
|
$signedReq = explode('.', $fb, 2); |
212
|
|
|
$payload = $signedReq[1]; |
213
|
|
|
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); |
214
|
|
|
$session->offsetSet('signed_request', $data); |
215
|
|
|
|
216
|
|
|
// This fix exists only for safari on Windows : we need to redirect the user to the page outside of iframe |
217
|
|
|
// for the cookie to be accepted. Core just adds a 'redir_fb_page_id' var to alert controllers |
218
|
|
|
// that they need to send the user back to FB... |
219
|
|
|
|
220
|
|
|
if (!count($_COOKIE) > 0 && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')) { |
221
|
|
|
echo '<script type="text/javascript">' . |
222
|
|
|
'window.top.location.href = window.location.href+"?redir_fb_page_id='. $data["page"]["id"]. '";' . |
223
|
|
|
'</script>'; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
// This fix exists only for IE6+, when this app is embedded into an iFrame : The P3P policy has to be set. |
227
|
|
|
$response = $e->getResponse(); |
|
|
|
|
228
|
|
|
if ($response instanceof \Zend\Http\Response && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strpos($_SERVER['HTTP_USER_AGENT'], 'rv:11.'))) { |
229
|
|
|
$response->getHeaders()->addHeaderLine('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function getAutoloaderConfig() |
236
|
|
|
{ |
237
|
|
|
return array( |
238
|
|
|
'Zend\Loader\ClassMapAutoloader' => array( |
239
|
|
|
__DIR__ . '/../../autoload_classmap.php', |
240
|
|
|
), |
241
|
|
|
'Zend\Loader\StandardAutoloader' => array( |
242
|
|
|
'namespaces' => array( |
243
|
|
|
__NAMESPACE__ => __DIR__ . '/../../src/' . __NAMESPACE__, |
244
|
|
|
), |
245
|
|
|
), |
246
|
|
|
); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function getConfig() |
250
|
|
|
{ |
251
|
|
|
return include __DIR__ . '/../../config/module.config.php'; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function getViewHelperConfig() |
255
|
|
|
{ |
256
|
|
|
return array( |
257
|
|
|
'factories' => array( |
258
|
|
|
'QgCKEditor' => function (\Zend\ServiceManager\ServiceManager $sm) { |
259
|
|
|
$config = $sm->getServiceLocator()->get('config'); |
|
|
|
|
260
|
|
|
$QuCk = new View\Helper\AdCKEditor($config['playgroundcore']['ckeditor']); |
261
|
|
|
|
262
|
|
|
return $QuCk; |
263
|
|
|
}, |
264
|
|
|
|
265
|
|
|
'googleAnalytics' => function (\Zend\ServiceManager\ServiceManager $sm) { |
266
|
|
|
$tracker = $sm->getServiceLocator()->get('google-analytics'); |
|
|
|
|
267
|
|
|
|
268
|
|
|
$helper = new View\Helper\GoogleAnalytics($tracker, $sm->getServiceLocator()->get('Request')); |
|
|
|
|
269
|
|
|
|
270
|
|
|
return $helper; |
271
|
|
|
}, |
272
|
|
|
|
273
|
|
|
'facebookOpengraph' => function (\Zend\ServiceManager\ServiceManager $sm) { |
274
|
|
|
$tracker = $sm->getServiceLocator()->get('facebook-opengraph'); |
|
|
|
|
275
|
|
|
|
276
|
|
|
$helper = new View\Helper\FacebookOpengraph($tracker, $sm->getServiceLocator()->get('Request')); |
|
|
|
|
277
|
|
|
|
278
|
|
|
return $helper; |
279
|
|
|
}, |
280
|
|
|
|
281
|
|
|
'twitterCard' => function (\Zend\ServiceManager\ServiceManager $sm) { |
282
|
|
|
$viewHelper = new View\Helper\TwitterCard(); |
283
|
|
|
$viewHelper->setConfig($sm->getServiceLocator()->get('twitter-card')); |
|
|
|
|
284
|
|
|
$viewHelper->setRequest($sm->getServiceLocator()->get('Request')); |
|
|
|
|
285
|
|
|
|
286
|
|
|
return $viewHelper; |
287
|
|
|
}, |
288
|
|
|
|
289
|
|
|
'switchLocaleWidget' => function (\Zend\ServiceManager\ServiceManager $sm) { |
290
|
|
|
$viewHelper = new View\Helper\SwitchLocaleWidget(); |
291
|
|
|
$viewHelper->setLocaleService($sm->getServiceLocator()->get('playgroundcore_locale_service')); |
|
|
|
|
292
|
|
|
$viewHelper->setWebsiteService($sm->getServiceLocator()->get('playgroundcore_website_service')); |
|
|
|
|
293
|
|
|
$viewHelper->setRouteMatch($sm->getServiceLocator()->get('application')->getMvcEvent()->getRouteMatch()); |
|
|
|
|
294
|
|
|
|
295
|
|
|
return $viewHelper; |
296
|
|
|
}, |
297
|
|
|
|
298
|
|
|
'countryName' => function (\Zend\ServiceManager\ServiceManager $sm) { |
299
|
|
|
$service = $sm->getServiceLocator()->get('playgroundcore_country_service'); |
|
|
|
|
300
|
|
|
$viewHelper = new View\Helper\CountryName($service); |
301
|
|
|
|
302
|
|
|
return $viewHelper; |
303
|
|
|
}, |
304
|
|
|
), |
305
|
|
|
); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
public function getServiceConfig() |
309
|
|
|
{ |
310
|
|
|
return array( |
311
|
|
|
|
312
|
|
|
'aliases' => array( |
313
|
|
|
'playgroundcore_doctrine_em' => 'doctrine.entitymanager.orm_default', |
314
|
|
|
'google-analytics' => 'PlaygroundCore\Analytics\Tracker', |
315
|
|
|
'facebook-opengraph' => 'PlaygroundCore\Opengraph\Tracker', |
316
|
|
|
'twitter-card' => 'PlaygroundCore\TwitterCard\Config', |
317
|
|
|
'twilio' => 'playgroundcore_twilio', |
318
|
|
|
'ffmpeg' => 'playgroundcore_phpvideotoolkit' |
319
|
|
|
), |
320
|
|
|
|
321
|
|
|
'shared' => array( |
322
|
|
|
'playgroundcore_message' => false, |
323
|
|
|
// don't want this service to be a singleton. I have to reset the ffmpeg parameters for each call. |
324
|
|
|
'playgroundcore_ffmpeg_service' => false |
325
|
|
|
), |
326
|
|
|
|
327
|
|
|
'invokables' => array( |
328
|
|
|
'Zend\Session\SessionManager' => 'Zend\Session\SessionManager', |
329
|
|
|
'playgroundcore_message' => 'PlaygroundCore\Mail\Service\Message', |
330
|
|
|
'playgroundcore_cron_service' => 'PlaygroundCore\Service\Cron', |
331
|
|
|
'playgroundcore_shortenurl_service' => 'PlaygroundCore\Service\ShortenUrl', |
332
|
|
|
'playgroundcore_website_service' => 'PlaygroundCore\Service\Website', |
333
|
|
|
'playgroundcore_locale_service' => 'PlaygroundCore\Service\Locale', |
334
|
|
|
'playgroundcore_formgen_service' => 'PlaygroundCore\Service\Formgen', |
335
|
|
|
'playgroundcore_image_service' => 'PlaygroundCore\Service\Image', |
336
|
|
|
'playgroundcore_ffmpeg_service' => 'PlaygroundCore\Service\Ffmpeg', |
337
|
|
|
'playgroundcore_country_service' => 'PlaygroundCore\Service\Country', |
338
|
|
|
), |
339
|
|
|
'factories' => array( |
340
|
|
|
'playgroundcore_module_options' => function (\Zend\ServiceManager\ServiceManager $sm) { |
341
|
|
|
$config = $sm->get('Configuration'); |
342
|
|
|
|
343
|
|
|
return new Options\ModuleOptions(isset($config['playgroundcore']) ? $config['playgroundcore'] : array()); |
344
|
|
|
}, |
345
|
|
|
|
346
|
|
|
'playgroundcore_formgen_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
347
|
|
|
return new Mapper\Formgen($sm->get('playgroundcore_doctrine_em'), $sm->get('playgroundcore_module_options')); |
|
|
|
|
348
|
|
|
}, |
349
|
|
|
|
350
|
|
|
'playgroundcore_website_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
351
|
|
|
|
352
|
|
|
return new Mapper\Website($sm->get('playgroundcore_doctrine_em'), $sm->get('playgroundcore_module_options')); |
|
|
|
|
353
|
|
|
}, |
354
|
|
|
|
355
|
|
|
'playgroundcore_locale_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
356
|
|
|
return new Mapper\Locale($sm->get('playgroundcore_doctrine_em'), $sm->get('playgroundcore_module_options')); |
|
|
|
|
357
|
|
|
}, |
358
|
|
|
|
359
|
|
|
'playgroundcore_twilio' => 'PlaygroundCore\Service\Factory\TwilioServiceFactory', |
360
|
|
|
'playgroundcore_phpvideotoolkit' => 'PlaygroundCore\Service\Factory\PhpvideotoolkitServiceFactory', |
361
|
|
|
'playgroundcore_transport' => 'PlaygroundCore\Mail\Transport\Service\TransportFactory', |
362
|
|
|
'PlaygroundCore\Analytics\Tracker' => function (\Zend\ServiceManager\ServiceManager $sm) { |
363
|
|
|
$config = $sm->get('config'); |
364
|
|
|
$config = isset($config['playgroundcore']) ? $config['playgroundcore']['googleAnalytics'] : array('id' => 'UA-XXXXXXXX-X'); |
365
|
|
|
|
366
|
|
|
$tracker = new Analytics\Tracker($config['id']); |
367
|
|
|
|
368
|
|
|
if (isset($config['enable_tracking'])) { |
369
|
|
|
$tracker->setEnableTracking($config['enable_tracking']); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
if (isset($config['custom_vars'])) { |
373
|
|
|
foreach ($config['custom_vars'] as $customVar) { |
374
|
|
|
$customVarId = $customVar['id']; |
375
|
|
|
$customVarName = $customVar['name']; |
376
|
|
|
$customVarValue = $customVar['value']; |
377
|
|
|
$customVarOptScope = $customVar['optScope']; |
378
|
|
|
$customVar = new Analytics\CustomVar($customVarId, $customVarName, $customVarValue, $customVarOptScope); |
379
|
|
|
$tracker->addCustomVar($customVar); |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
if (isset($config['domain_name'])) { |
384
|
|
|
$tracker->setDomainName($config['domain_name']); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
if (isset($config['allow_linker'])) { |
388
|
|
|
$tracker->setAllowLinker($config['allow_linker']); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
if (isset($config['allow_hash'])) { |
392
|
|
|
$tracker->setAllowHash($config['allow_hash']); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return $tracker; |
396
|
|
|
}, |
397
|
|
|
'PlaygroundCore\Opengraph\Tracker' => function (\Zend\ServiceManager\ServiceManager $sm) { |
398
|
|
|
$config = $sm->get('config'); |
399
|
|
|
$config = isset($config['playgroundcore']['facebookOpengraph']) ? $config['playgroundcore']['facebookOpengraph'] : array('appId' => ''); |
400
|
|
|
|
401
|
|
|
$tracker = new Opengraph\Tracker($config['appId']); |
402
|
|
|
|
403
|
|
|
if (isset($config['enable'])) { |
404
|
|
|
$tracker->setEnableOpengraph($config['enable']); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
if (isset($config['tags'])) { |
408
|
|
|
foreach ($config['tags'] as $type => $value) { |
409
|
|
|
$tag = new Opengraph\Tag($type, $value); |
410
|
|
|
$tracker->addTag($tag); |
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
return $tracker; |
415
|
|
|
}, |
416
|
|
|
'PlaygroundCore\TwitterCard\Config' => function (\Zend\ServiceManager\ServiceManager $sm) { |
417
|
|
|
$config = $sm->get('config'); |
418
|
|
|
$config = isset($config['playgroundcore']['twitterCard']) ? $config['playgroundcore']['twitterCard'] : array(); |
419
|
|
|
return new TwitterCard\Config($config); |
420
|
|
|
}, |
421
|
|
|
), |
422
|
|
|
); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
public function getConsoleUsage(\Zend\Console\Adapter\Posix $console) |
|
|
|
|
426
|
|
|
{ |
427
|
|
|
return array( |
428
|
|
|
'cron' => 'call this command to enable cron tasks' |
429
|
|
|
); |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.