/** * Gets the redirect url. * * @param string $platform * * @return string */ protected function getRedirectUrl($platform) { if ($routingOption = $this->getRoutingOption($platform)) { if (self::REDIRECT === $routingOption) { // Make sure to hint at the device override, otherwise infinite loop // redirections may occur if different device views are hosted on // different domains (since the cookie can't be shared across domains) $queryParams = $this->container->get('request')->query->all(); $queryParams[$this->deviceView->getSwitchParam()] = $platform; return rtrim($this->redirectConf[$platform]['host'], '/') . $this->container->get('request')->getPathInfo() . '?' . Request::normalizeQueryString(http_build_query($queryParams)); } elseif (self::REDIRECT_WITHOUT_PATH === $routingOption) { // Make sure to hint at the device override, otherwise infinite loop // redirections may occur if different device views are hosted on // different domains (since the cookie can't be shared across domains) return $this->redirectConf[$platform]['host'] . '?' . $this->deviceView->getSwitchParam() . '=' . $platform; } else { return null; } } else { return null; } }
/** * Gets the RedirectResponse for the specified view. * * @param string $view The view for which we want the RedirectResponse. * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ protected function getRedirectResponse($view) { if ($host = $this->getRedirectUrl($view)) { return $this->deviceView->getRedirectResponse($view, $host, $this->redirectConf[$view]['status_code']); } }
/** * Collects data for the given Request and Response. * * @param Request $request A Request instance * @param Response $response A Response instance * @param \Exception $exception An Exception instance * * @api */ public function collect(Request $request, Response $response, \Exception $exception = null) { $this->data['currentView'] = $this->deviceView->getViewType(); $this->data['views'] = array(array('label' => 'Full', 'link' => $this->generateSwitchLink($request, DeviceView::VIEW_FULL), 'isCurrent' => $this->deviceView->isFullView()), array('label' => 'Tablet', 'link' => $this->generateSwitchLink($request, DeviceView::VIEW_TABLET), 'isCurrent' => $this->deviceView->isTabletView()), array('label' => 'Mobile', 'link' => $this->generateSwitchLink($request, DeviceView::VIEW_MOBILE), 'isCurrent' => $this->deviceView->isMobileView())); }