Beispiel #1
0
 /**
  * @param        $output
  * @param string $errorOutput
  *
  * @return Response
  */
 protected function parseOutput($output, $errorOutput = '')
 {
     $response = new Response();
     list($header, $body) = explode("\r\n\r\n", $output, 2);
     $response->setBody($body);
     $response->setError($errorOutput);
     $header = new Text($header);
     $cookies = [];
     foreach ($header->lines() as $line) {
         list($name, $value) = explode(':', $line, 2);
         if ('Set-Cookie' == $name) {
             $cookies[] = trim($value);
         } else {
             $response->setHeader(trim($name), trim($value));
         }
     }
     if (count($cookies)) {
         $response->setHeader('Set-Cookie', $cookies);
     }
     return $response;
 }
Beispiel #2
0
 /**
  * @param int        $code
  * @param \Exception $e
  *
  * @return Response
  */
 protected function handleError($code, \Exception $e)
 {
     $path = __DIR__ . sprintf('/Resources/html/%d.html', $code);
     if (file_exists($path)) {
         $response = new Response(file_get_contents($path), $code);
     } else {
         $response = new Response(sprintf('<html><body><h1>Error %d</h1><p>%s</p></body></html>', $code, $e->getMessage()), $code);
     }
     return $response->setError($e->getMessage());
 }