Example #1
0
 public function getStatus()
 {
     if ($this->exception instanceof HttpError) {
         return $this->exception->getStatus();
     }
     return WebResponse::STATUS_SERVER_ERROR;
 }
Example #2
0
 /**
  * getStatus() should return int if status does exist
  */
 public function test_getStatus_returnsInt_ifStatusDoesExist()
 {
     $status = 500;
     $exception = new Exception();
     $exception->setStatus($status);
     $this->assertEquals($status, $exception->getStatus());
     return;
 }
Example #3
0
 /**
  * Send the $exception's code or $code as the formal HTTP status of the response.
  *
  * @param  integer    $code  suggested HTTP response code, if exception fails to provide one
  * @param  Exception  $exception   OPTIONAL HTTP status code
  * @return string   status code and description
  */
 private static function setHeaderStatus($code, Exception $exception = null)
 {
     if ($exception instanceof ZFDemo_Exception_Reroute) {
         $status = $exception->getStatus();
     } else {
         switch ($code) {
             case 404:
                 $status = '404 Not Found';
                 break;
             case 500:
                 $status = '500 Internal Server Error';
                 break;
             default:
                 require_once 'Zend/Http/Response.php';
                 $status = $code . ' ' . Zend_Http_Response::responseCodeAsText($code);
         }
     }
     if ('cgi' !== substr(php_sapi_name(), 0, 3) && !empty($_SERVER['SERVER_PROTOCOL'])) {
         header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status, true);
     } else {
         header('Status: ' . $status, true);
     }
     return $status;
 }
Example #4
0
 /**
  * @param \Exception $exception
  * @throws \Exception
  * @return self
  */
 public function setException(\Exception $exception)
 {
     if ($exception instanceof Exception && null !== $exception->getStatus()) {
         $this->setStatus($exception->getStatus())->setContent($exception->getMessage() . "\n");
     } else {
         throw $exception;
     }
     return $this;
 }
Example #5
0
 /**
  * Send the $exception's code or $code as the formal HTTP status of the response.
  *
  * @param  integer    $code  suggested HTTP response code, if exception fails to provide one
  * @param  Exception  $exception   OPTIONAL HTTP status code
  * @return string   status code and description
  */
 private static function setHeaderStatus($code, Exception $exception = null)
 {
     if ($exception instanceof ZFDemo_Exception_Reroute) {
         $status = $exception->getStatus();
     } else {
         switch ($code) {
             case 404:
                 $status = '404 Not Found';
                 break;
             case 500:
                 $status = '500 Internal Server Error';
                 break;
             default:
                 require_once 'Zend/Http/Response.php';
                 $status = $code . ' ' . Zend_Http_Response::responseCodeAsText($code);
         }
     }
     if ('cgi' !== substr(php_sapi_name(), 0, 3) && !empty($_SERVER['SERVER_PROTOCOL'])) {
         header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status, true);
     } else {
         header('Status: ' . $status, true);
     }
     /////////////////////////////
     // ==> SECTION: email <==
     if (intval(substr($status, 0, 3)) >= 500) {
         // if the error $code is serious (e.g. 500-599 application errors),
         self::notifyAdmin($code, $status);
         // then send an email to the admin
     }
     return $status;
 }