Example #1
0
 /**
  * Exception handler
  *
  * This will log the exception and output the exception properties
  * formatted as html or a 500 response depending on your application config
  *
  * @param object The uncaught exception
  */
 public static function exception($e)
 {
     static::log($e);
     if (Config::error('report')) {
         // clear output buffer
         while (ob_get_level() > 1) {
             ob_end_clean();
         }
         if (Request::cli()) {
             Cli::write(PHP_EOL . 'Uncaught Exception', 'light_red');
             Cli::write($e->getMessage() . PHP_EOL);
             Cli::write('Origin', 'light_red');
             Cli::write(substr($e->getFile(), strlen(PATH)) . ' on line ' . $e->getLine() . PHP_EOL);
             Cli::write('Trace', 'light_red');
             Cli::write($e->getTraceAsString() . PHP_EOL);
         } else {
             $html = file_get_contents(PATH . '../assets/error_document.tpl.html');
             $lines = explode("\n", htmlentities(file_get_contents($e->getFile())));
             $line = $e->getLine();
             $file = $e->getFile();
             $start_line = $line - 5 <= 0 ? 0 : $line - 5;
             $file_contents = array_slice($lines, $start_line, 1);
             $array = ['debug.message' => $e->getMessage(), 'debug.location' => "<strong>{$file}</strong> on line <strong>{$line}</strong>", 'debug.backtrace' => $e->getTraceAsString(), 'copyright.year' => date('Y')];
             foreach ($array as $find => $replace) {
                 $html = str_replace('{{' . $find . '}}', $replace, $html);
             }
             echo $html;
         }
     } else {
         // issue a 500 response
         Response::error(500, array('exception' => $e))->send();
     }
     exit(1);
 }
Example #2
0
 protected function _active($actives)
 {
     $result = '';
     foreach ($actives as $i => $item) {
         if (\Request::is($item)) {
             return ' active selected open';
         }
     }
     return $result;
 }
Example #3
0
 /**
  * Create a new instance of the Router class for chaining
  *
  * @return object
  */
 public static function create()
 {
     if (Request::cli()) {
         // get cli arguments
         $args = Arr::get($_SERVER, 'argv', array());
         $uri = implode('/', array_slice($args, 1));
         return new static('cli', trim($uri, '/') ?: '/');
     }
     return new static(Request::method(), Uri::current());
 }
Example #4
0
 /**
  * Search a set of routes for the route matching a method and URI.
  *
  * @return Route
  */
 public function route()
 {
     // Check for a literal route match first. If we find one, there is
     // no need to spin through all of the routes.
     if (isset($this->routes[$this->request])) {
         return Request::$route = new Route($this->request, $this->routes[$this->request]);
     }
     foreach ($this->routes as $keys => $callback) {
         // Only check routes that have multiple URIs or wildcards.
         // Other routes would have been caught by the check for literal matches.
         if (strpos($keys, '(') !== false or strpos($keys, ',') !== false) {
             foreach (explode(', ', $keys) as $key) {
                 if (preg_match('#^' . $this->translate_wildcards($key) . '$#', $this->request)) {
                     return Request::$route = new Route($keys, $callback, $this->parameters($this->request, $key));
                 }
             }
         }
     }
 }
Example #5
0
    /**
     * Exception handler
     *
     * This will log the exception and output the exception properties
     * formatted as html or a 500 response depending on your application config
     *
     * @param object The uncaught exception
     */
    public static function exception($e)
    {
        static::log($e);
        if (Config::error('report')) {
            // clear output buffer
            while (ob_get_level() > 1) {
                ob_end_clean();
            }
            if (Request::cli()) {
                Cli::write(PHP_EOL . 'Uncaught Exception', 'light_red');
                Cli::write($e->getMessage() . PHP_EOL);
                Cli::write('Origin', 'light_red');
                Cli::write(substr($e->getFile(), strlen(PATH)) . ' on line ' . $e->getLine() . PHP_EOL);
                Cli::write('Trace', 'light_red');
                Cli::write($e->getTraceAsString() . PHP_EOL);
            } else {
                echo '<html>
					<head>
						<title>Uncaught Exception</title>
						<style>
							body{font-family:"Open Sans",arial,sans-serif;background:#FFF;color:#333;margin:2em}
							code{background:#D1E751;border-radius:4px;padding:2px 6px}
						</style>
					</head>
					<body>
						<h1>Uncaught Exception</h1>
						<p><code>' . $e->getMessage() . '</code></p>
						<h3>Origin</h3>
						<p><code>' . substr($e->getFile(), strlen(PATH)) . ' on line ' . $e->getLine() . '</code></p>
						<h3>Trace</h3>
						<pre>' . $e->getTraceAsString() . '</pre>
					</body>
					</html>';
            }
        } else {
            // issue a 500 response
            Response::error(500, array('exception' => $e))->send();
        }
        exit(1);
    }
Example #6
0
 /**
  * Sends the final headers cookies and output
  */
 public function send()
 {
     // dont send headers for CLI
     if (!Request::cli()) {
         // create a status header
         Status::create($this->status)->header();
         // always make sure we send the content type
         if (!array_key_exists('content-type', $this->headers)) {
             $this->headers['content-type'] = 'text/html; charset=' . Config::app('encoding', 'UTF-8');
         }
         // output headers
         foreach ($this->headers as $name => $value) {
             header($name . ': ' . $value);
         }
         // send any cookies we may have stored in the cookie class
         foreach (Cookie::$bag as $cookie) {
             call_user_func_array('setcookie', array_values($cookie));
         }
     }
     // output the final content
     if ($this->output) {
         echo $this->output;
     }
 }
Example #7
0
 /**
  * Create an instance or the Status class
  *
  * @param int
  */
 public function __construct($status = 200)
 {
     $this->status = $status;
     $this->protocol = Request::protocol();
 }