/** * 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); }
/** * 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); }
/** * Execute the route function. * * @param mixed $route * @param array $parameters * @return Response */ public function call() { $response = null; // The callback may be in array form, meaning it has attached filters or is named and we // will need to evaluate it further to determine what to do. If the callback is just a // closure, we can execute it now and return the result. if (is_callable($this->callback)) { $response = call_user_func_array($this->callback, $this->parameters); } elseif (is_array($this->callback)) { if (isset($this->callback['needs'])) { Package::load(explode(', ', $this->callback['needs'])); } $response = isset($this->callback['before']) ? Filter::call($this->callback['before'], array(), true) : null; if (is_null($response) and !is_null($handler = $this->find_route_function())) { $response = call_user_func_array($handler, $this->parameters); } } $response = Response::prepare($response); if (is_array($this->callback) and isset($this->callback['after'])) { Filter::call($this->callback['after'], array($response)); } return $response; }
/** * Calls the route actions and returns a response object * * @return object */ public function run() { // Call before actions $response = $this->before(); // If we didn't get a response run the main callback if (is_null($response)) { $response = call_user_func_array($this->callbacks['main'], $this->args); } // Call any after actions $this->after($response); // If we have a response object return it if ($response instanceof Response) { return $response; } // If the response was a view get the output and create response if ($response instanceof View) { $response = $response->render(); } elseif (is_object($response) and method_exists($response, '__toString')) { $response = (string) $response; } elseif (ob_get_length()) { $response = ob_get_clean(); } return Response::create($response); }
/** Returneaza proprietatile pentru afisarea formularului insert/update/delete in functie de actiunea solicitata. Proprietatile sunt: 1) actiunea (insert/update/delete) 2) caption 3) text button submit **/ public function get_dtform_properties($form, $input) { $model = $this->model($input['model']); $record = $input['action'] != 'insert' ? $model::getRecord($input['record_id']) : NULL; return \Response::json(['action' => $input['action'], 'caption' => $this->caption($form->captions->{$input['action']}, $record), 'button' => $form->buttons->{$input['action']}, 'record' => $record]); }
/** * Get the detailed error report for the exception. * * @return Response */ private function detailed_response() { $data = array('severity' => $this->exception->severity(), 'message' => $this->exception->message(), 'line' => $this->exception->getLine(), 'trace' => $this->exception->getTraceAsString(), 'contexts' => $this->exception->context()); return Response::make(View::make('error.exception', $data), 500); }