예제 #1
0
파일: RouteProvider.php 프로젝트: sulu/sulu
 /**
  * Will create a symfony route.
  *
  * @param RouteInterface $route
  * @param Request $request
  *
  * @return Route
  */
 protected function createRoute(RouteInterface $route, Request $request)
 {
     $routePath = $this->requestAnalyzer->getResourceLocatorPrefix() . $route->getPath();
     if ($route->isHistory()) {
         return new Route($routePath, ['_controller' => 'SuluWebsiteBundle:Redirect:redirect', 'url' => $request->getSchemeAndHttpHost() . $this->requestAnalyzer->getResourceLocatorPrefix() . $route->getTarget()->getPath() . ($request->getQueryString() ? '?' . $request->getQueryString() : '')]);
     }
     $symfonyRoute = $this->proxyFactory->createProxy(Route::class, function (&$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) use($routePath, $route, $request) {
         $initializer = null;
         // disable initialization
         $wrappedObject = new Route($routePath, $this->routeDefaultsProvider->getByEntity($route->getEntityClass(), $route->getEntityId(), $request->getLocale()));
         return true;
     });
     return $this->symfonyRouteCache[$route->getId()] = $symfonyRoute;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function render($object, $id, $webspaceKey, $locale, $partial = false)
 {
     $portalInformations = $this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale($webspaceKey, $locale, $this->environment);
     if (count($portalInformations) === 0) {
         throw new PortalNotFoundException($object, $id, $webspaceKey, $locale);
     }
     if (!$this->routeDefaultsProvider->supports(get_class($object))) {
         throw new RouteDefaultsProviderNotFoundException($object, $id, $webspaceKey, $locale);
     }
     /** @var PortalInformation $portalInformation */
     $portalInformation = reset($portalInformations);
     $webspace = $portalInformation->getWebspace();
     $localization = $webspace->getLocalization($locale);
     $query = [];
     $request = [];
     $cookies = [];
     $currentRequest = $this->requestStack->getCurrentRequest();
     if ($currentRequest !== null) {
         $query = $currentRequest->query->all();
         $request = $currentRequest->request->all();
         $cookies = $currentRequest->cookies->all();
     }
     $attributes = new RequestAttributes(['webspace' => $webspace, 'locale' => $locale, 'localization' => $localization, 'portal' => $portalInformation->getPortal(), 'portalUrl' => $portalInformation->getUrl(), 'resourceLocatorPrefix' => $portalInformation->getPrefix(), 'getParameters' => $query, 'postParameters' => $request, 'analyticsKey' => $this->previewDefaults['analyticsKey'], 'portalInformation' => $portalInformation]);
     $defaults = $this->routeDefaultsProvider->getByEntity(get_class($object), $id, $locale, $object);
     // Controller arguments
     $defaults['object'] = $object;
     $defaults['preview'] = true;
     $defaults['partial'] = $partial;
     $defaults['_sulu'] = $attributes;
     $request = new Request($query, $request, $defaults, $cookies);
     $request->setLocale($locale);
     $this->eventDispatcher->dispatch(Events::PRE_RENDER, new PreRenderEvent($attributes));
     try {
         $response = $this->handle($request);
     } catch (\Twig_Error $e) {
         throw new TwigException($e, $object, $id, $webspace, $locale);
     } catch (\InvalidArgumentException $e) {
         throw new TemplateNotFoundException($e, $object, $id, $webspace, $locale);
     } catch (\Exception $e) {
         throw new UnexpectedException($e, $object, $id, $webspace, $locale);
     }
     return $response->getContent();
 }