/** * @param \HumusMvc\MvcEvent $e * @return void */ public function __invoke(MvcEvent $e) { $serviceManager = $e->getApplication()->getServiceManager(); $config = $serviceManager->get('Config'); if (!isset($config['locale'])) { // no locale config found, return return; } // set cache in locale to speed up application if ($serviceManager->has('CacheManager')) { $cacheManager = $serviceManager->get('CacheManager'); Locale::setCache($cacheManager->getCache('default')); } $options = $config['locale']; if (!isset($options['default'])) { $locale = new Locale(); } elseif (!isset($options['force']) || (bool) $options['force'] == false) { // Don't force any locale, just go for auto detection Locale::setDefault($options['default']); $locale = new Locale(); } else { $locale = new Locale($options['default']); } $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY; Registry::set($key, $locale); }
/** * Listen to the "dispatch" event * * @param MvcEvent $e * @return mixed */ public function onDispatch(MvcEvent $e) { $application = $e->getApplication(); $sm = $application->getServiceManager(); $front = $sm->get('FrontController'); $front->returnResponse(true); // Response must be always returned $response = $front->dispatch(); return $this->complete($response, $e); }