public function switchAction(Request $request)
    {
        $theme = $request->get('theme');

        if (!in_array($theme, $this->themes)) {
            throw new NotFoundHttpException(sprintf('The theme "%s" does not exist', $theme));
        }

        $this->activeTheme->setName($theme);

        $url = $request->headers->get('Referer', '/');
        $response = new RedirectResponse($url);

        if (!empty($this->cookieOptions)) {
            $cookie = new Cookie(
                $this->cookieOptions['name'],
                $theme,
                time() + $this->cookieOptions['lifetime'],
                $this->cookieOptions['path'],
                $this->cookieOptions['domain'],
                (bool) $this->cookieOptions['secure'],
                (bool) $this->cookieOptions['http_only']
            );

            $response->headers->setCookie($cookie);
        }

        return $response;
    }