示例#1
0
 /**
  * @param EnlightResponse $response
  * @return SymfonyResponse
  */
 public function transformEnlightResponseToSymfonyResponse(EnlightResponse $response)
 {
     $rawHeaders = $response->getHeaders();
     $headers = array();
     foreach ($rawHeaders as $header) {
         if (!isset($headers[$header['name']]) || !empty($header['replace'])) {
             header_remove($header['name']);
             $headers[$header['name']] = array($header['value']);
         } else {
             $headers[$header['name']][] = $header['value'];
         }
     }
     $symfonyResponse = new SymfonyResponse($response->getBody(), $response->getHttpResponseCode(), $headers);
     foreach ($response->getCookies() as $cookieName => $cookieContent) {
         $sfCookie = new Cookie($cookieName, $cookieContent['value'], $cookieContent['expire'], $cookieContent['path'], $cookieContent['domain'], (bool) $cookieContent['secure'], (bool) $cookieContent['httpOnly']);
         $symfonyResponse->headers->setCookie($sfCookie);
     }
     return $symfonyResponse;
 }
示例#2
0
    /**
     * @param \Enlight_Controller_Response_ResponseHttp $response
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function createResponse(ControllerResponse $response)
    {
        $rawHeaders = $response->getHeaders();
        $headers = array();
        foreach($rawHeaders as $header) {
            if(!isset($headers[$header['name']]) || !empty($header['replace'])) {
                $headers[$header['name']] = array($header['value']);
            } else {
                $headers[$header['name']][] = $header['value'];
            }
        }
        //todo@hl Maybe transform to symfony
        $response->sendCookies();

        return new Response(
            $response->getBody(),
            $response->getHttpResponseCode(),
            $headers
        );
    }