findPortalInformationsByUrl() public method

Returns all portal which matches the given url (which has not necessarily to be the main url).
public findPortalInformationsByUrl ( string $url, string $environment ) : PortalInformation[]
$url string The url to search for
$environment string The environment in which the url should be searched
return Sulu\Component\Webspace\PortalInformation[]
 /**
  * {@inheritdoc}
  */
 public function process(Request $request, RequestAttributes $requestAttributes)
 {
     $url = rtrim(sprintf('%s%s', $request->getHost(), $request->getRequestUri()), '/');
     if (substr($url, -5, 5) === '.html') {
         $url = substr($url, 0, -5);
     }
     $portalInformations = $this->webspaceManager->findPortalInformationsByUrl($url, $this->environment);
     if (count($portalInformations) === 0) {
         return new RequestAttributes();
     }
     /** @var PortalInformation[] $portalInformations */
     $portalInformations = array_filter($portalInformations, function (PortalInformation $portalInformation) {
         return $portalInformation->getType() === RequestAnalyzer::MATCH_TYPE_WILDCARD;
     });
     foreach ($portalInformations as $portalInformation) {
         if (!$portalInformation->getWebspace()) {
             continue;
         }
         if (null !== ($attributes = $this->matchCustomUrl($url, $portalInformation, $request))) {
             return new RequestAttributes($attributes);
         }
     }
     return new RequestAttributes();
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function process(Request $request, RequestAttributes $requestAttributes)
 {
     $host = $request->getHttpHost();
     $url = $host . $request->getPathInfo();
     foreach ($this->webspaceManager->getPortalInformations($this->environment) as $portalInformation) {
         $portalUrl = $this->replacer->replaceHost($portalInformation->getUrl(), $host);
         $portalInformation->setUrl($portalUrl);
         $portalRedirect = $this->replacer->replaceHost($portalInformation->getRedirect(), $host);
         $portalInformation->setRedirect($portalRedirect);
     }
     $portalInformations = $this->webspaceManager->findPortalInformationsByUrl($url, $this->environment);
     if (count($portalInformations) === 0) {
         return new RequestAttributes();
     }
     usort($portalInformations, function (PortalInformation $a, PortalInformation $b) {
         if ($a->getPriority() === $b->getPriority()) {
             return strlen($a->getUrl()) < strlen($b->getUrl());
         }
         return $a->getPriority() < $b->getPriority();
     });
     /** @var PortalInformation $portalInformation */
     $portalInformation = reset($portalInformations);
     return new RequestAttributes(['portalInformation' => $portalInformation]);
 }