/** * Accepts PHP Errors and Exceptions and displays custom debugger. * * dynamic params: * 1. mixed $error Object if Exception, error_number if standard * PHP error. * 2. string $string Optional for PHP Error * 3. string $file Optional for PHP Error * 4. integer $line Optional for PHP Error * * @static */ public static function handler() { // Exceptions will contain only an object $args = func_get_args(); /* * When error reporting is disabled, we do nothing. * In the case of '@' error control operator, this handler will still be called * with an error_reporting level of integer 0. */ if (!error_reporting()) { return TRUE; } try { // Build debugger $debugger = new \component\View('debugger'); switch (count($args)) { // Errors will supply 2-5 parameters case 5: $debugger->context = $args[4]; case 4: $debugger->line_number = $args[3]; case 3: $debugger->file_name = $args[2]; case 2: $debugger->message = $args[1]; $debugger->error_type = self::getErrorType($args[0]); $debugger->backtrace = debug_backtrace(); break; // Exceptions will supply only an object // Exceptions will supply only an object case 1: $exception = $args[0]; $debugger->message = $exception->getMessage(); $debugger->file_name = $exception->getFile(); $debugger->line_number = $exception->getLine(); $debugger->error_type = get_class($exception); $debugger->backtrace = $exception->getTrace(); break; default: die('Invalid number of arguments supplied to Core Exception handler.'); break; } // Flush any open output buffers. We only want to see errors. ob_get_clean(); // Show error Core::$draw = FALSE; if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } $debugger->display(); } catch (\Exception $e) { print "Error occurred in Framework Exception Handler: " . $e->getMessage(); print '. Try issuing a \\Core::fault($args) in various places to track it down.'; } exit; }
/** * Demonstrate the \component\Example adapter. * Also demonstrates JSON output using specialized view adapter. */ public function adapter() { // Original input. $input = array('a' => 1, 'b' => 2, 'c' => 3); // We want to override and add some values. $altValues = array('c' => array(4, 5, 6), 'd' => 'hello world'); // Build adapter object. $adapter = new \component\Example($input, $altValues); // Get modified output. $output = $adapter->getOutput(); // Attach original, untouched input data. $output['originalValues'] = $adapter->getInput(); // Issue JSON response. $view = new \component\View('response', 'json'); $view->data = $output; $view->status = 'generated'; $view->display(); }
/** * Dump helper. * Outputs any number of supplied arguments with fancy display. * * @param ... ... ... */ public static function dump() { // Do not display in production mode. if (!IN_PRODUCTION) { $arguments = func_get_args(); $dump = new component\View('dump'); $dump->data = $arguments; $dump->count = count($arguments); $dump->display(); } }
/** * Accepts PHP Errors and Exceptions and displays custom debugger. * * dynamic params: * 1. mixed $error Object if Exception, error_number if standard * PHP error. * 2. string $string Optional for PHP Error * 3. string $file Optional for PHP Error * 4. integer $line Optional for PHP Error * * @static */ public static function handler() { // Exceptions will contain only an object $args = func_get_args(); try { // Build debugger $debugger = new \component\View('debugger'); switch (count($args)) { // Errors will supply 2-5 parameters case 5: $debugger->context = $args[4]; case 4: $debugger->line_number = $args[3]; case 3: $debugger->file_name = $args[2]; case 2: $debugger->message = $args[1]; $debugger->error_type = self::getErrorType($args[0]); $debugger->backtrace = debug_backtrace(); break; // Exceptions will supply only an object // Exceptions will supply only an object case 1: $exception = $args[0]; $debugger->message = $exception->getMessage(); $debugger->file_name = $exception->getFile(); $debugger->line_number = $exception->getLine(); $debugger->error_type = get_class($exception); $debugger->backtrace = $exception->getTrace(); break; default: die('Invalid number of arguments supplied to Core Exception handler.'); break; } // Flush any open output buffers. We only want to see errors. ob_get_clean(); // Show error Core::$draw = FALSE; header('HTTP/1.1 500 Internal Server Error'); $debugger->display(); } catch (\Exception $e) { print "Error occurred in Framework Exception Handler: " . $e->getMessage(); } exit; }