Beispiel #1
0
 /**
  * Renders an error template for PHP errors and Exceptions
  */
 public function _onException($e)
 {
     $response = new Response();
     $error = $this->_filterError($e);
     $data = ["status" => $this->_status, "title" => $this->_status . ": " . $error["type"], "description" => "There has been a problem of type (" . $error["type"] . ").", "address" => Server::getUrl(), "method" => Connection::getMethod(), "date" => date("F jS Y h:i:s A T"), "headers" => getallheaders(), "error" => $error];
     // send error data to log file
     $this->log($error["type"] . ": " . $error["message"] . " in " . $error["file"] . " on line " . $error["line"] . ".");
     // send http reposnse
     if (Connection::isMethod("GET")) {
         // template has been set...
         if (!empty($this->_template) && is_file($this->_template)) {
             // send all data to template to be rendered as needed
             $response->sendTemplate($this->_status, $this->_template, $data);
         }
         // no template, send just error description for security reasons
         $response->sendText($this->_status, $data["description"]);
     }
     // non-GET, send error description data as JSON
     $response->sendJson($this->_status, ["status" => $this->_status, "error" => $data["description"]]);
 }
Beispiel #2
0
 /**
  * Send default response depending on request method and response type
  */
 public function sendDefault($status, $response = null, $data = [])
 {
     if (Connection::isMethod("GET")) {
         if (is_object($response)) {
             $this->sendView($status, $response);
         }
         if (is_array($response)) {
             $this->sendText($status, print_r($response, true));
         }
         if (is_string($response)) {
             if (is_file($response)) {
                 $this->sendTemplate($status, $response, $data);
             }
             $this->sendText($status, $response);
         }
         $this->sendText($status, "Empty response.");
     }
     $this->sendJson($status, array_merge(Sanitize::toArray($response), $data));
 }