getAttribute() public method

Returns request attribute with given name.
public getAttribute ( string $name, mixed | null $default = null ) : mixed
$name string
$default mixed | null
return mixed
コード例 #1
0
ファイル: AppendAnalyticsListener.php プロジェクト: sulu/sulu
 /**
  * Appends analytics scripts into body.
  *
  * @param FilterResponseEvent $event
  */
 public function onResponse(FilterResponseEvent $event)
 {
     if (0 !== strpos($event->getResponse()->headers->get('Content-Type'), 'text/html') || $this->requestAnalyzer->getPortalInformation() === null) {
         return;
     }
     $portalUrl = $this->requestAnalyzer->getAttribute('urlExpression');
     $analytics = $this->analyticsRepository->findByUrl($portalUrl, $this->requestAnalyzer->getPortalInformation()->getWebspaceKey(), $this->environment);
     $content = $this->engine->render('SuluWebsiteBundle:Analytics:website.html.twig', ['analytics' => $analytics]);
     $response = $event->getResponse();
     $responseContent = $response->getContent();
     $response->setContent(str_replace('</body>', $content . '</body>', $responseContent));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getContentPath($route, $webspaceKey = null, $locale = null, $domain = null, $scheme = null, $withoutDomain = true)
 {
     // if the request analyzer null or a route is passed which is relative or inclusive a domain nothing should be
     // done (this is important for external-links in navigations)
     if (!$this->requestAnalyzer || strpos($route, '/') !== 0) {
         return $route;
     }
     $scheme = $scheme ?: $this->requestAnalyzer->getAttribute('scheme');
     $locale = $locale ?: $this->requestAnalyzer->getCurrentLocalization()->getLocale();
     $webspaceKey = $webspaceKey ?: $this->requestAnalyzer->getWebspace()->getKey();
     $url = null;
     $host = $this->requestAnalyzer->getAttribute('host');
     if (!$domain && $this->webspaceManager->findWebspaceByKey($webspaceKey)->hasDomain($host, $this->environment)) {
         $domain = $host;
     }
     $url = $this->webspaceManager->findUrlByResourceLocator($route, $this->environment, $locale, $webspaceKey, $domain, $scheme);
     if (!$withoutDomain && !$url) {
         $url = $this->webspaceManager->findUrlByResourceLocator($route, $this->environment, $locale, $webspaceKey, null, $scheme);
     }
     return $url ?: $route;
 }
コード例 #3
0
ファイル: CustomUrlRouteProvider.php プロジェクト: sulu/sulu
 /**
  * {@inheritdoc}
  */
 public function getRouteCollectionForRequest(Request $request)
 {
     $collection = new RouteCollection();
     $routeDocument = $this->requestAnalyzer->getAttribute('customUrlRoute');
     $customUrlDocument = $this->requestAnalyzer->getAttribute('customUrl');
     $localization = $this->requestAnalyzer->getAttribute('localization');
     if (null === $routeDocument || null === $localization) {
         return $collection;
     }
     if ($routeDocument->isHistory()) {
         // if custom-url is not redirect to avoid double redirects.
         if (!$routeDocument->getTargetDocument()->getTargetDocument()->isRedirect()) {
             return $this->addHistoryRedirectToRouteCollection($request, $routeDocument, $collection, $this->requestAnalyzer->getWebspace()->getKey());
         }
         $routeDocument = $routeDocument->getTargetDocument();
         $customUrlDocument = $routeDocument->getTargetDocument();
     }
     if ($customUrlDocument === null || $customUrlDocument->isPublished() === false || $customUrlDocument->getTargetDocument() !== null && $customUrlDocument->getTargetDocument()->getWorkflowStage() !== WorkflowStage::PUBLISHED) {
         return $collection;
     }
     $collection->add(uniqid('custom_url_route_', true), new Route($request->getPathInfo(), ['_custom_url' => $customUrlDocument, '_webspace' => $this->requestAnalyzer->getWebspace(), '_environment' => $this->environment]));
     return $collection;
 }