예제 #1
0
파일: ErrorHandler.php 프로젝트: pdyn/base
 /**
  * Handle uncaught exceptions.
  *
  * @param \Exception $exception An uncaught exception.
  */
 public static function exception_handler(\Exception $exception)
 {
     global $CFG, $USR;
     $errcode = $exception->getCode();
     $errmsg = $exception->getMessage();
     $errcodelabel = $exception instanceof \pdyn\base\Exception ? $exception->get_string_from_code($errcode) : static::getinternalerrorlabel($errcode);
     if (\pdyn\base\Utils::is_cli_env() === true) {
         echo 'APP ERROR: ' . $errcodelabel . ': ' . $errmsg . "\n";
     } else {
         // Atlas exceptions' error codes are HTTP status codes, so send one.
         if ($exception instanceof \pdyn\base\Exception && !empty($errcode) && !headers_sent()) {
             \pdyn\httputils\Utils::send_status_code($errcode, '', false);
         } else {
             \pdyn\httputils\Utils::send_status_code(500, '', false);
         }
         $LOG = new \pdyn\log\Logger($CFG->log_general);
         $LOG->error($errcodelabel . ': ' . $exception);
         if (isset($_GET['ajax'])) {
             header('Content-type: application/json');
             echo json_encode(['result' => 'fail', 'msg' => $errcodelabel . ': ' . $errmsg]);
         } else {
             $debugmode = !empty($CFG) && (bool) $CFG->get('core', 'debugmode', false) === true ? true : false;
             $isadmin = !empty($USR) && $USR->is_admin === true ? true : false;
             $backtrace = $isadmin === true || $debugmode === true ? static::format_backtrace($exception->getTrace()) : null;
             static::write_error_html($errcodelabel, $errmsg, $errcode, $backtrace);
         }
     }
     die;
 }
예제 #2
0
 /**
  * Send a response to the client.
  *
  * @param int $httpcode An HTTP code to send.
  * @param string $msg A message to send.
  */
 protected function send_response($httpcode, $msg)
 {
     \pdyn\httputils\Utils::die_with_status_code($httpcode, $msg);
 }
예제 #3
0
파일: Minifier.php 프로젝트: pdyn/min
 /**
  * Send headers to assist with caching.
  *
  * thanks to Rich Bradshaw (http://stackoverflow.com/users/16511/rich-bradshaw)
  * from http://stackoverflow.com/questions/2000715/answering-http-if-modified-since-and-http-if-none-match-in-php
  *
  * @param string $file The file we want cached.
  * @param int $timestamp Last modification time of the file.
  */
 protected function caching_headers($file, $timestamp = null)
 {
     \pdyn\httputils\Utils::caching_headers($file, $timestamp, false);
 }