Example #1
0
 /**
  * Dump the routes exposed to javascript to '/web/js/fos_js_routes.js'
  *
  * @param null $lang
  * @return string
  * @throws \Exception
  */
 public function dumpJsRoutes($lang = null)
 {
     // determine list of supported languages
     $langs = array();
     $installedLanguages = \ZLanguage::getInstalledLanguages();
     if (isset($lang) && in_array($lang, $installedLanguages)) {
         // use provided lang if available
         $langs = array($lang);
     } else {
         $multilingual = (bool) \System::getVar('multilingual', 0);
         if ($multilingual) {
             // get all available locales
             $langs = $installedLanguages;
         } else {
             // get only the default locale
             $langs = array(\System::getVar('language_i18n', 'en'));
             //$this->container->getParameter('locale');
         }
     }
     $errors = '';
     // force deletion of existing file
     $targetPath = sprintf('%s/../web/js/fos_js_routes.js', $this->container->getParameter('kernel.root_dir'));
     if (file_exists($targetPath)) {
         try {
             unlink($targetPath);
         } catch (\Exception $e) {
             $errors .= __f("Error: Could not delete '%s' because %s", array($targetPath, $e->getMessage()));
         }
     }
     foreach ($langs as $lang) {
         $command = new DumpCommand();
         $command->setContainer($this->container);
         $input = new ArrayInput(array('--locale' => $lang . I18nLoader::ROUTING_PREFIX));
         $output = new NullOutput();
         try {
             $command->run($input, $output);
         } catch (\RuntimeException $e) {
             $errors .= $e->getMessage() . ". ";
         }
     }
     return $errors;
 }