Example #1
0
 /**
  * {@inheritDoc}
  */
 public function assemble(Event $event)
 {
     $uri = $event->getUri();
     $locale = $event->getLocale();
     $query = $uri->getQueryAsArray();
     $key = $this->getQueryKey();
     $query[$key] = $locale;
     $uri->setQuery($query);
     return $uri;
 }
Example #2
0
 /**
  * @param Event $event
  * @return void
  */
 public function found(Event $event)
 {
     $locale = $event->getLocale();
     $request = $event->getRequest();
     $cookieName = $this->getCookieName();
     if (!$this->isHttpRequest($request)) {
         return;
     }
     $cookie = $request->getCookie();
     // Omit Set-Cookie header when cookie is present
     if ($cookie instanceof Cookie && $cookie->offsetExists($cookieName) && $locale === $cookie->offsetGet($cookieName)) {
         return;
     }
     $path = '/';
     if (method_exists($request, 'getBasePath')) {
         $path = rtrim($request->getBasePath(), '/') . '/';
     }
     $response = $event->getResponse();
     $setCookie = new SetCookie($cookieName, $locale, null, $path);
     $response->getHeaders()->addHeader($setCookie);
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function found(Event $event)
 {
     $request = $event->getRequest();
     if (!$this->isHttpRequest($request) || !$event->hasLocales()) {
         return;
     }
     $locale = $event->getLocale();
     if (null === $locale) {
         return;
     }
     // By default, use the alias to redirect to
     if (!$this->redirectToCanonical()) {
         $locale = $this->getAliasForLocale($locale);
     }
     $host = str_replace(self::LOCALE_KEY, $locale, $this->getDomain());
     $uri = $request->getUri();
     if ($host === $uri->getHost()) {
         return;
     }
     $uri->setHost($host);
     $response = $event->getResponse();
     $response->setStatusCode(self::REDIRECT_STATUS_CODE);
     $response->getHeaders()->addHeaderLine('Location', $uri->toString());
     return $response;
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function assemble(Event $event)
 {
     $uri = $event->getUri();
     $base = $this->getBasePath();
     $locale = $event->getLocale();
     $current = $this->getFirstSegmentInPath($uri, $base);
     if (!$this->redirectToCanonical() && $this->getAliases()) {
         $alias = $this->getAliasForLocale($locale);
         if (null !== $alias) {
             $locale = $alias;
         }
     }
     $path = $uri->getPath();
     // Last part of base is now always locale, remove that
     $parts = explode('/', trim($base, '/'));
     array_pop($parts);
     $base = implode('/', $parts);
     if ($base) {
         $path = substr($path, strlen($base));
     }
     $parts = explode('/', trim($path, '/'));
     // Remove first part
     array_shift($parts);
     $path = $base . '/' . $locale . '/' . implode('/', $parts);
     $uri->setPath($path);
     return $uri;
 }