Example #1
0
 /**
  * Replaces the given values in the pattern.
  *
  * @param string $pattern
  * @param array $replacers
  *
  * @return string
  */
 private function generateUrlAddress($pattern, $replacers)
 {
     foreach ($replacers as $replacer => $value) {
         $pattern = $this->urlReplacer->replace($pattern, $replacer, $value);
     }
     return $pattern;
 }
Example #2
0
 /**
  * Localize given domain.
  *
  * @param string $domain
  * @param Localization $locale
  *
  * @return string
  */
 protected function localizeDomain($domain, Localization $locale)
 {
     if (!$this->urlReplacer->hasLocalizationReplacer($domain) && !$this->urlReplacer->hasLanguageReplacer($domain)) {
         $domain = $this->urlReplacer->appendLocalizationReplacer($domain);
     }
     $domain = $this->urlReplacer->replaceLanguage($domain, $locale->getLanguage());
     $domain = $this->urlReplacer->replaceCountry($domain, $locale->getCountry());
     $domain = $this->urlReplacer->replaceLocalization($domain, $locale->getLocalization());
     return $this->urlReplacer->cleanup($domain);
 }
Example #3
0
 /**
  * @return Route
  */
 protected function getRedirectWebSpaceRoute()
 {
     $localization = $this->defaultLocaleProvider->getDefaultLocale();
     $redirect = $this->requestAnalyzer->getRedirect();
     $redirect = $this->urlReplacer->replaceCountry($redirect, $localization->getCountry());
     $redirect = $this->urlReplacer->replaceLanguage($redirect, $localization->getLanguage());
     $redirect = $this->urlReplacer->replaceLocalization($redirect, $localization->getLocale(Localization::DASH));
     // redirect by information from webspace config
     // has to be done for all routes, because double slashes introduce problems otherwise
     return new Route('/{wildcard}', ['_controller' => 'SuluWebsiteBundle:Redirect:redirectWebspace', 'url' => $this->requestAnalyzer->getPortalUrl(), 'redirect' => $redirect], ['wildcard' => '.*']);
 }
Example #4
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 #5
0
 /**
  * {@inheritdoc}
  */
 public function invalidatePath($path, array $headers = [])
 {
     $path = $this->requestHost ? $this->replacer->replaceHost($path, $this->requestHost) : $path;
     $this->pathsToInvalidate[] = ['path' => $path, 'headers' => $headers];
 }