/** * @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); }
/** * Complete the dispatch * * @param Response $response * @param MvcEvent $event * @return mixed */ protected function complete(Response $response, MvcEvent $event) { $event->setResult($response); return $response; }
/** * Send the response * * @param MvcEvent $e * @return void */ public function sendResponse(MvcEvent $e) { $response = $e->getResponse(); $response->sendResponse(); }
/** * Bootstrap the application * * Defines and binds the MvcEvent, and passes it the request, response, and * router. Triggers the bootstrap event. * * @return Application */ public function bootstrap() { $serviceManager = $this->serviceManager; $events = $this->getEventManager(); $events->attach($serviceManager->get('DispatchListener')); $events->attach($serviceManager->get('SendResponseListener')); // Setup MVC Event $this->event = $event = new MvcEvent(); $event->setTarget($this); $event->setApplication($this)->setRequest($this->getRequest())->setResponse($this->getResponse())->setRouter($serviceManager->get('Router')); // Trigger bootstrap events $events->trigger(MvcEvent::EVENT_BOOTSTRAP, $event); return $this; }