public static function handleException(Exception $exception)
 {
     if (ob_get_level() > 1) {
         ob_end_clean();
     }
     if ($exception instanceof LibraryException) {
         // Special Case for LibraryException to shift front value from stack
         $exception = new RecessFrameworkException($exception->getMessage(), 1, $exception->getTrace());
     }
     if ($exception instanceof RecessResponseException) {
         header('HTTP/1.1 ' . ResponseCodes::getMessageForCode($exception->responseCode));
     } else {
         if (!headers_sent()) {
             header('HTTP/1.1 ' . ResponseCodes::getMessageForCode(ResponseCodes::HTTP_INTERNAL_SERVER_ERROR));
         }
     }
     if (!class_exists('RecessConf', false)) {
         print $exception->getMessage() . "\n";
         print $exception->getTraceAsString();
         print $exception->getFile() . ' ' . $exception->getLine();
         exit;
     }
     if (RecessConf::$mode == RecessConf::DEVELOPMENT) {
         include 'output/exception_report.php';
     } else {
         if ($exception instanceof RecessResponseException) {
             echo ResponseCodes::getMessageForCode($exception->responseCode);
         } else {
             echo ResponseCodes::getMessageForCode(ResponseCodes::HTTP_INTERNAL_SERVER_ERROR);
         }
         echo '<br />', $exception->getMessage();
     }
 }
 /**
  * Responsible for sending all headers in a Response. Marked final because
  * all headers should be bundled in Response object.
  *
  * @param Response $response
  * @final
  */
 protected function sendHeadersFor(Response $response)
 {
     header('HTTP/1.1 ' . ResponseCodes::getMessageForCode($response->code));
     $format = $response->request->accepts->format();
     header('Content-Type: ' . MimeTypes::preferredMimeTypeFor($format));
     foreach ($response->headers as $header) {
         header($header);
     }
     foreach ($response->getCookies() as $cookie) {
         if ($cookie->value == '') {
             setcookie($cookie->name, '', time() - 10000, $cookie->path, $cookie->domain, $cookie->secure, $cookie->httponly);
         } else {
             setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, $cookie->domain, $cookie->secure, $cookie->httponly);
         }
     }
     flush();
     // TODO: Determine other headers to send here. Content-Type, Caching, Etags, ...
 }
 public function __construct(Request $request)
 {
     parent::__construct($request, ResponseCodes::HTTP_NO_CONTENT, ResponseCodes::getMessageForCode(ResponseCodes::HTTP_NO_CONTENT));
 }
 public function __construct(Request $request)
 {
     parent::__construct($request, ResponseCodes::HTTP_NOT_IMPLEMENTED, ResponseCodes::getMessageForCode(ResponseCodes::HTTP_NOT_IMPLEMENTED));
 }
 public function __construct(Request $request)
 {
     parent::__construct($request, ResponseCodes::HTTP_BAD_REQUEST, ResponseCodes::getMessageForCode(ResponseCodes::HTTP_BAD_REQUEST));
 }
 public function __construct(Request $request)
 {
     parent::__construct($request, ResponseCodes::HTTP_INTERNAL_SERVER_ERROR, ResponseCodes::getMessageForCode(ResponseCodes::HTTP_INTERNAL_SERVER_ERROR));
 }
 public function __construct(Request $request)
 {
     parent::__construct($request, ResponseCodes::HTTP_FORBIDDEN, ResponseCodes::getMessageForCode(ResponseCodes::HTTP_FORBIDDEN));
 }
 public function __construct(Request $request, $methodsAllowed)
 {
     parent::__construct($request, ResponseCodes::HTTP_METHOD_NOT_ALLOWED, ResponseCodes::getMessageForCode(ResponseCodes::HTTP_METHOD_NOT_ALLOWED));
     $this->addHeader('Allow: ' . implode(', ', $methodsAllowed));
 }