replaceHost() public method

Replace host with given value.
public replaceHost ( string $url, string $host ) : string
$url string
$host string
return string
Example #1
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]);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function invalidatePath($path, array $headers = [])
 {
     $path = $this->requestHost ? $this->replacer->replaceHost($path, $this->requestHost) : $path;
     $this->pathsToInvalidate[] = ['path' => $path, 'headers' => $headers];
 }