Exemplo n.º 1
0
 /**
  * indexAction action.
  */
 public function indexAction(Request $request, $_format)
 {
     $session = $request->getSession();
     if ($request->hasPreviousSession() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
         // keep current flashes for one more request if using AutoExpireFlashBag
         $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
     }
     $cache = new ConfigCache($this->exposedRoutesExtractor->getCachePath($request->getLocale()), $this->debug);
     if (!$cache->isFresh()) {
         $exposedRoutes = $this->exposedRoutesExtractor->getRoutes();
         $serializedRoutes = $this->serializer->serialize($exposedRoutes, 'json');
         $cache->write($serializedRoutes, $this->exposedRoutesExtractor->getResources());
     } else {
         $serializedRoutes = file_get_contents((string) $cache);
         $exposedRoutes = $this->serializer->deserialize($serializedRoutes, 'Symfony\\Component\\Routing\\RouteCollection', 'json');
     }
     $routesResponse = new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $exposedRoutes, $this->exposedRoutesExtractor->getPrefix($request->getLocale()), $this->exposedRoutesExtractor->getHost(), $this->exposedRoutesExtractor->getScheme(), $request->getLocale());
     $content = $this->serializer->serialize($routesResponse, 'json');
     if (null !== ($callback = $request->query->get('callback'))) {
         $validator = new \JsonpCallbackValidator();
         if (!$validator->validate($callback)) {
             throw new HttpException(400, 'Invalid JSONP callback value');
         }
         $content = $callback . '(' . $content . ');';
     }
     $response = new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
     $this->cacheControlConfig->apply($response);
     return $response;
 }
Exemplo n.º 2
0
 /**
  * @param string $cacheDir
  * @param string $cachePrefix
  * @param string $kernelContainerClass
  * @param ExposedRoutesExtractorInterface $fosJsRoutesExtractor
  * @param array $routingLocales
  */
 public function __construct($cacheDir, $cachePrefix, $kernelContainerClass, $fosJsRoutesExtractor, $routingLocales)
 {
     $this->cacheDir = $cacheDir;
     $this->cachePrefix = $cachePrefix;
     $this->fs = new Filesystem();
     $cacheFolder = $cacheDir . DIRECTORY_SEPARATOR;
     $fosJsRoutingFiles = array();
     foreach ($routingLocales as $locale) {
         $fosJsRoutingFiles[] = $fosJsRoutesExtractor->getCachePath($locale);
     }
     $this->cacheTypes = array("symfony.annotations" => array("{$cacheFolder}/annotations"), "symfony.routing.generator" => array("{$cacheFolder}{$cachePrefix}UrlGenerator.php", "{$cacheFolder}{$cachePrefix}UrlGenerator.php.meta"), "symfony.routing.matcher" => array("{$cacheFolder}{$cachePrefix}UrlMatcher.php", "{$cacheFolder}{$cachePrefix}UrlMatcher.php.meta"), "symfony.routing.fosjs" => $fosJsRoutingFiles, "symfony.config" => array("{$cacheFolder}{$kernelContainerClass}.php", "{$cacheFolder}{$kernelContainerClass}.php.meta", "{$cacheFolder}{$kernelContainerClass}.xml", "{$cacheFolder}{$kernelContainerClass}Compiler.log", "{$cacheFolder}classes.map"));
 }