コード例 #1
0
 /**
  * Hook 3: Called in $this->setRequest.
  *
  * All resources have been loaded and the $request object is created.
  * Theoretically this event can be triggered multiple times, but this does
  * not happen in a standard Zend application.
  *
  * Not initialized are the $response and $controller objects.
  *
  * Previous hook: beforeRun()
  * Actions since: $this->request object created
  * Actions after: $this->response object created
  * Next hook: responseChanged()
  *
  * @param \Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function requestChanged(\Zend_Controller_Request_Abstract $request)
 {
     if ($this->project->isMultiLocale()) {
         // Get the choosen language
         $localeId = \Gems_Cookies::getLocale($request);
         // Change when $localeId exists and is different from session
         if ($localeId && $this->locale->getLanguage() !== $localeId) {
             // \MUtil_Echo::r('On cookie ' . $localeId . ' <> ' . $this->locale->getLanguage());
             // Does the locale exist?
             if (isset($this->project->locales[$localeId])) {
                 // Add and implement the choosen locale
                 $this->session->user_locale = $localeId;
                 $this->locale->setLocale($localeId);
                 if (!$this->translate->isAvailable($localeId)) {
                     $languageFilename = APPLICATION_PATH . '/languages/default-' . $localeId . '.mo';
                     if (file_exists($languageFilename)) {
                         $this->translate->addTranslation($languageFilename, $localeId);
                     }
                 }
                 $this->translate->setLocale($localeId);
                 $this->translateAdapter = $this->translate->getAdapter();
             }
         }
     }
     // Set the base path, the route is now fixed
     $this->basepath->setBasePath($request->getBasePath());
     // Set the jQuery version and other information needed
     // by classes using jQuery
     $jquery = \MUtil_JQuery::jQuery();
     $jqueryVersion = '1.11.1';
     $jqueryUiVersion = '1.11.1';
     $jquery->setVersion($jqueryVersion);
     $jquery->setUiVersion($jqueryUiVersion);
     if ($this->project->isJQueryLocal()) {
         $jqueryDir = $request->getBasePath() . $this->project->getJQueryLocal();
         $jquery->setLocalPath($jqueryDir . 'jquery-' . $jqueryVersion . '.js');
         $jquery->setUiLocalPath($jqueryDir . 'jquery-ui-' . $jqueryUiVersion . '.js');
     } else {
         if (\MUtil_Https::on()) {
             $jquery->setCdnSsl(true);
         }
     }
     if (\MUtil_Bootstrap::enabled() && $this->project->isBootstrapLocal()) {
         $bootstrap = \MUtil_Bootstrap::bootstrap();
         $basePath = $request->getBasePath();
         $bootstrap->setBootstrapScriptPath($basePath . '/bootstrap/js/bootstrap.min.js');
         $bootstrap->setBootstrapStylePath($basePath . '/bootstrap/css/bootstrap.min.css');
         $bootstrap->setFontAwesomeStylePath($basePath . '/bootstrap/css/font-awesome.min.css');
     }
 }