Exemplo n.º 1
0
 /**
  * Shutdown function to catch fatal errors.
  * @return void
  */
 public static function checkFatal()
 {
     $error = error_get_last();
     if ($error && static::isFatal($error['type'])) {
         Yolk::exception(new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
     }
 }
Exemplo n.º 2
0
 function dd()
 {
     if (Yolk::isDebug()) {
         headers_sent() || header('Content-type: text/plain; charset=UTF-8');
         foreach (func_get_args() as $arg) {
             Yolk::dump($arg);
         }
         die;
     }
 }
Exemplo n.º 3
0
 public function extra($key = null, $default = null)
 {
     if (is_array($key)) {
         $this->extra = $key;
         return $this;
     } else {
         return Yolk::get($this->extra, $key, $default);
     }
 }
 protected function error(\Exception $error, $context = [])
 {
     // if this isn't a 404 then log it and if we're in debug mode then throw it to Yolk's exception handler
     if (!$error instanceof exceptions\NotFoundException) {
         if (Yolk::isDebug()) {
             throw $error;
         }
         error_log(get_class($error) . ': ' . $error->getMessage() . ' [' . $error->getFile() . ':' . $error->getLine() . ']');
     }
     // default to a 500 error
     $code = 500;
     $message = 'Internal Server Error';
     // if it's an application error then use the code and message provided
     if ($error instanceof Exception) {
         $code = $error->getCode();
         $message = $error->getMessage();
     }
     // send an appropriate header if we still can
     if (!headers_sent()) {
         header("HTTP/1.1 {$code} {$message}");
     }
     // do we have a specific error page?
     if (file_exists("{$this->path}/app/errors/{$code}.php")) {
         include "{$this->path}/app/errors/{$code}.php";
     } elseif (file_exists("{$this->path}/app/errors/generic.php")) {
         include "{$this->path}/app/errors/generic.php";
     } else {
         throw $error;
     }
 }