Example #1
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Unable to write file /tmp
  */
 public function testExecuteUnableToWriteFile()
 {
     $this->container->expects($this->at(0))->method('get')->with('fos_js_routing.extractor')->will($this->returnValue($this->extractor));
     $this->serializer->expects($this->once())->method('serialize')->will($this->returnValue('{"base_url":"","routes":{"literal":{"tokens":[["text","\\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\\/","[^\\/]++","slug"],["text","\\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""}'));
     $this->container->expects($this->at(1))->method('get')->with('fos_js_routing.serializer')->will($this->returnValue($this->serializer));
     $command = new DumpCommand();
     $command->setContainer($this->container);
     $tester = new CommandTester($command);
     $tester->execute(array('--target' => '/tmp'));
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $webPath = sprintf('%s/../web/', $this->getContainer()->getParameter('kernel.root_dir'));
     $targetPath = $webPath . self::DUMP_TARGET_PATH;
     $input->setOption("target", $targetPath);
     parent::initialize($input, $output);
 }
Example #3
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;
 }
 /**
  * {@inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     // override default target file
     if (!$input->getOption('target')) {
         $webRootDir = $this->getContainer()->getParameter('assetic.read_from');
         if ($webRootDir) {
             $input->setOption('target', $webRootDir . '/js/routes.js');
         }
     }
     parent::initialize($input, $output);
 }