/** * A helper method that dumps the current backtrace to the client * * @return NULL */ public static function dump() { if (\r8\Env::request()->isCLI()) { $format = new \r8\Backtrace\Formatter\Text(); } else { $format = new \r8\Backtrace\Formatter\HTML(); } echo r8(new \r8\Backtrace\Formatter($format))->format(self::create()->popEvent()); }
/** * Dumps the content of a variable to the output buffer * * This works exactly like var_dump, except it detects if it needs to wrap the output in <pre> tags * * @param mixed $value The value to dump */ function dump($value) { if (\r8\Env::request()->isCLI()) { var_dump($value); } else { echo "<pre>"; var_dump($value); echo "</pre>"; } }
public function testFormat() { $formatter = new \r8\Error\Formatter\HTML(\r8\Env::request()); $exception = new \r8\Exception("Test", 5050); $exception->addData("key", "data"); $exception->addData("test", new stdClass()); $error = new \r8\Error\Exception($exception); $result = $formatter->format($error); $this->assertType("string", $result); $this->assertGreaterThan(0, strlen($result)); }
/** * Constructor... * * @param String $name The name of this form field * @param String|NULL $label The label that describes this input field * @param \r8\Validator\FileUpload $validator The validator to use * for checking the uploaded file. If left empty, a default * instance will be created * @param \r8\Input\Files $files The list of uploaded files to pull * this fields value from. If left empty, the File list from * the global Request will be used */ public function __construct($name, $label = null, \r8\Validator\FileUpload $validator = null, \r8\Input\Files $files = null) { parent::__construct($name, $label); $this->validator = $validator ?: new \r8\Validator\FileUpload(); $this->files = $files ?: \r8\Env::request()->getFiles(); }
/** * Returns a string about this exception * * @return String */ public function __toString() { if (\r8\Env::request()->isCLI()) { $formatter = new \r8\Error\Formatter\Text(\r8\Env::request()); } else { $formatter = new \r8\Error\Formatter\HTML(\r8\Env::request()); } return $formatter->format($this); }
*/ \r8\Autoload::getInstance()->register('r8', r8_DIR_CLASSES)->register('r8\\iface', r8_DIR_INTERFACES)->register('r8\\Test', r8_DIR_TEST); spl_autoload_register(array(\r8\Autoload::getInstance(), "load")); /** * Take a snapshot of the environment */ \r8\Env::Request(); /** * Set up error handling, but only if it isn't being suppressed by the including code */ if (!defined("r8_SUPPRESS_HANDLERS")) { // Register the error handler set_error_handler(function ($code, $message, $file, $line) { $level = (int) ini_get('error_reporting'); $code = (int) $code; if (!($code & $level)) { return TRUE; } $backtrace = \r8\Backtrace::create()->popEvent(); \r8\Error::getInstance()->handle(new \r8\Error\PHP($file, $line, $code, $message, $backtrace)); }); // Register an exception handler set_exception_handler(function ($exception) { \r8\Error::getInstance()->handle(new \r8\Error\Exception($exception)); }); // Hook in the error handler to the error log \r8\Error::getInstance()->register(new \r8\Error\Handler\Stream(new \r8\Error\Formatter\JSON(\r8\Env::request()), new \r8\Stream\Out\ErrorLog())); // Hook in the error handler to output the error to the client \r8\Error::getInstance()->register(new \r8\Error\Handler\IniDisplay(new \r8\Error\Handler\Stream(\r8\Env::request()->isCLI() ? new \r8\Error\Formatter\Text(\r8\Env::request()) : new \r8\Error\Formatter\HTML(\r8\Env::request()), new \r8\Stream\Out\StdOut()))); } // @codeCoverageIgnoreEnd
/** * Processes a list of input arguments * * @param \r8\CLI\Input $input If left empty, this will pull the input * from the environment * @return \r8\CLI\Result */ public function process(\r8\CLI\Input $input = NULL) { if (empty($input)) { $input = \r8\Env::request()->getCLIArgs(); } $firstError = NULL; foreach ($this->forms as $form) { try { $input->rewind(); return $form->process($input); } catch (\r8\Exception\Data $err) { if (!isset($firstError)) { $firstError = $err; } } } throw $firstError; }