示例#1
0
 /**
  * @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);
 }
示例#2
0
 /**
  * Complete the dispatch
  *
  * @param  Response $response
  * @param  MvcEvent $event
  * @return mixed
  */
 protected function complete(Response $response, MvcEvent $event)
 {
     $event->setResult($response);
     return $response;
 }
示例#3
0
 /**
  * Send the response
  *
  * @param  MvcEvent $e
  * @return void
  */
 public function sendResponse(MvcEvent $e)
 {
     $response = $e->getResponse();
     $response->sendResponse();
 }
示例#4
0
 /**
  * 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;
 }