The expected data is a simple associative array. Any nested arrays
will be flattened with print_r
public addDataTable ( string $label, array $data ) | ||
$label | string | |
$data | array |
public function __invoke($request, $response, $next) { $container = $this->app->getContainer(); $settings = DotArray::newDotArray($container['settings']); if ($settings['app.debug'] === true) { // Enable PrettyPageHandler with editor options $prettyPageHandler = new PrettyPageHandler(); if ($settings->has('whoops.editor')) { $prettyPageHandler->setEditor($settings['whoops.editor']); } // Enable JsonResponseHandler when request is AJAX $jsonResponseHandler = new JsonResponseHandler(); $jsonResponseHandler->onlyForAjaxRequests(true); // Add more information to the PrettyPageHandler $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($this->app), 'Script Name' => $this->app->environment->get('SCRIPT_NAME'), 'Request URI' => $this->app->environment->get('PATH_INFO') ?: '<none>']); $prettyPageHandler->addDataTable('Slim Application (Request)', ['Accept Charset' => $this->app->request->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $this->app->request->getContentCharset() ?: '<none>', 'Path' => $this->app->request->getUri()->getPath(), 'Query String' => $this->app->request->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $this->app->request->getMethod(), 'Base URL' => (string) $this->app->request->getUri(), 'Scheme' => $this->app->request->getUri()->getScheme(), 'Port' => $this->app->request->getUri()->getPort(), 'Host' => $this->app->request->getUri()->getHost()]); $prettyPageHandler->addDataTable('SlimFastShake Settings', $settings->flatten()); // Set Whoops to default exception handler $whoops = new \Whoops\Run(); $whoops->pushHandler($prettyPageHandler); $whoops->pushHandler($jsonResponseHandler); if (isset($container['logger'])) { $logger = $container['logger']; $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { $logger->critical('Whoops: ' . $exception->getMessage()); }); } $whoops->register(); $container['errorHandler'] = function ($c) use($whoops) { return new WhoopsErrorHandler($whoops); }; $container['whoops'] = $whoops; } return $next($request, $response); }
public function __invoke($request, $response, $next) { $app = $next; $container = $app->getContainer(); $settings = $container['settings']; if (isset($settings['debug']) === true && $settings['debug'] === true) { // Enable PrettyPageHandler with editor options $prettyPageHandler = new PrettyPageHandler(); if (empty($settings['whoops.editor']) === false) { $prettyPageHandler->setEditor($settings['whoops.editor']); } // Enable JsonResponseHandler when request is AJAX $jsonResponseHandler = new JsonResponseHandler(); $jsonResponseHandler->onlyForAjaxRequests(true); // Add more information to the PrettyPageHandler $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($app), 'Script Name' => $app->environment->get('SCRIPT_NAME'), 'Request URI' => $app->environment->get('PATH_INFO') ?: '<none>']); $prettyPageHandler->addDataTable('Slim Application (Request)', array('Accept Charset' => $app->request->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $app->request->getContentCharset() ?: '<none>', 'Path' => $app->request->getUri()->getPath(), 'Query String' => $app->request->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $app->request->getMethod(), 'Base URL' => (string) $app->request->getUri(), 'Scheme' => $app->request->getUri()->getScheme(), 'Port' => $app->request->getUri()->getPort(), 'Host' => $app->request->getUri()->getHost())); // Set Whoops to default exception handler $whoops = new \Whoops\Run(); $whoops->pushHandler($prettyPageHandler); $whoops->pushHandler($jsonResponseHandler); $whoops->register(); $container['errorHandler'] = function ($c) use($whoops) { return new WhoopsErrorHandler($whoops); }; // $container['whoops'] = $whoops; } return $app($request, $response); }
/** * Prepare the Whoops page handler with a table displaying request information * * @param Request $request */ private function prepareWhoopsHandler(Request $request) { if ($request instanceof StratigilityRequest) { $request = $request->getOriginalRequest(); } $uri = $request->getUri(); $this->whoopsHandler->addDataTable('Expressive Application Request', ['HTTP Method' => $request->getMethod(), 'URI' => (string) $uri, 'Script' => $request->getServerParams()['SCRIPT_NAME'], 'Headers' => $request->getHeaders(), 'Cookies' => $request->getCookieParams(), 'Attributes' => $request->getAttributes(), 'Query String Arguments' => $request->getQueryParams(), 'Body Params' => $request->getParsedBody()]); }
/** * Instantiate Whoops with the correct handlers. */ public function __construct() { require 'YiiWhoopsRunner.php'; $this->whoops = new YiiWhoopsRunner(); if (Yii::app()->request->isAjaxRequest) { $this->whoops->pushHandler(new JsonResponseHandler()); } else { $contentType = ''; foreach (headers_list() as $header) { list($key, $value) = explode(':', $header); $value = ltrim($value, ' '); if (strtolower($key) === 'content-type') { // Split encoding if exists $contentType = explode(";", strtolower($value)); $contentType = current($contentType); break; } } if ($contentType && strpos($contentType, 'json')) { $this->whoops->pushHandler(new JsonResponseHandler()); } else { $page_handler = new PrettyPageHandler(); if ($this->pageTitle) { $page_handler->setPageTitle($this->pageTitle); } $reordered_tables = array('Request information' => static::createRequestTable(), "GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Environment Variables" => $_ENV, "Server/Request Data" => $_SERVER); foreach ($reordered_tables as $label => $data) { $page_handler->addDataTable($label, $data); } $this->whoops->pushHandler($page_handler); } } }
public function __invoke(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, $next) { $container = $this->app->getContainer(); $settings = $container['settings']; // Enable PrettyPageHandler with editor options $prettyPageHandler = new PrettyPageHandler(); // Enable JsonResponseHandler when request is AJAX $jsonResponseHandler = new JsonResponseHandler(); $jsonResponseHandler->onlyForAjaxRequests(true); // Add more information to the PrettyPageHandler $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($this->app), 'Script Name' => $this->app->environment->get('SCRIPT_NAME'), 'Request URI' => $this->app->environment->get('PATH_INFO') ?: '<none>']); $prettyPageHandler->addDataTable('Slim Application (Request)', array('Accept Charset' => $this->app->request->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $this->app->request->getContentCharset() ?: '<none>', 'Path' => $this->app->request->getUri()->getPath(), 'Query String' => $this->app->request->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $this->app->request->getMethod(), 'Base URL' => (string) $this->app->request->getUri(), 'Scheme' => $this->app->request->getUri()->getScheme(), 'Port' => $this->app->request->getUri()->getPort(), 'Host' => $this->app->request->getUri()->getHost())); // Set Whoops to default exception handler $whoops = new \Whoops\Run(); $whoops->pushHandler($prettyPageHandler); $whoops->pushHandler($jsonResponseHandler); if (!empty($logger = $this->logger)) { $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { $logger->error($exception->getMessage()); }); } $whoops->register(); // Overwrite the errorHandler $container['errorHandler'] = function ($c) use($whoops) { return function ($request, $response, $exception) use($whoops) { if ($exception instanceof BooBoo) { // Store the BooBoo error body response in a buffer ob_start(); BooBoo::exceptionHandler($exception); $buffer = ob_get_contents(); ob_end_clean(); // By creating a new response object, all the headers set by BooBoo get resynced $response = new \HTTP\Response(); return $response->overwrite($buffer); } else { $handler = \Whoops\Run::EXCEPTION_HANDLER; ob_start(); $whoops->{$handler}($exception); $content = ob_get_clean(); $code = $exception instanceof HttpException ? $exception->getStatusCode() : 500; return $response->withStatus($code)->withHeader('Content-type', 'text/html')->write($content); } }; }; return $next($request, $response); }
public function setErrorTraits($traits) { $run = new Run(); $handler = new PrettyPageHandler(); $handler->addDataTable('Traits', $traits); $run->pushHandler($handler); $run->register(); }
public function __invoke($request, $response, $next) { $container = $this->app->getContainer(); $settings = $container['settings']; if (isset($settings['debug']) === true && $settings['debug'] === true) { // Enable PrettyPageHandler with editor options $prettyPageHandler = new PrettyPageHandler(); if (empty($settings['whoops.editor']) === false) { $prettyPageHandler->setEditor($settings['whoops.editor']); } // Enable JsonResponseHandler when request is AJAX $jsonResponseHandler = new JsonResponseHandler(); $jsonResponseHandler->onlyForAjaxRequests(true); // Add more information to the PrettyPageHandler $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($this->app), 'Script Name' => $container['environment']->get('SCRIPT_NAME'), 'Request URI' => $container['environment']->get('PATH_INFO') ?: '<none>']); $prettyPageHandler->addDataTable('Slim Application (Request)', array('Accept Charset' => $container['request']->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $container['request']->getContentCharset() ?: '<none>', 'Path' => $container['request']->getUri()->getPath(), 'Query String' => $container['request']->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $container['request']->getMethod(), 'Base URL' => (string) $container['request']->getUri(), 'Scheme' => $container['request']->getUri()->getScheme(), 'Port' => $container['request']->getUri()->getPort(), 'Host' => $container['request']->getUri()->getHost())); // Set Whoops to default exception handler $whoops = new \Whoops\Run(); $whoops->pushHandler($prettyPageHandler); $whoops->pushHandler($jsonResponseHandler); /*// Setup Monolog, for example: $logger = new \Monolog\Logger('Test'); $logger->pushHandler(new \Monolog\Handler\StreamHandler("c:/xampp/php/logs/php_error_log"));*/ // Place our custom handler in front of the others, capturing exceptions // and logging them, then passing the exception on to the other handlers: if (!empty($logger = $this->logger)) { $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { $logger->error($exception->getMessage()); }); } $whoops->register(); $container['errorHandler'] = function ($c) use($whoops) { return function ($request, $response, $exception) use($whoops) { $handler = \Whoops\Run::EXCEPTION_HANDLER; ob_start(); $whoops->{$handler}($exception); $content = ob_get_clean(); $code = $exception instanceof HttpException ? $exception->getStatusCode() : 500; return $response->withStatus($code)->withHeader('Content-type', 'text/html')->write($content); }; }; // $container['whoops'] = $whoops; } return $next($request, $response); }
static function reload() { $run = new Whoops\Run(); $handler = new PrettyPageHandler(); $CI =& get_instance(); $handler->setEditor("sublime"); // Set the editor used for the "Open" link $handler->addDataTable("Extra Info", array("Name" => 'Forhad Ahmed', "email" => "*****@*****.**")); // Set the title of the error page: $handler->setPageTitle("Whoops! There was a problem."); $run->pushHandler($handler); $CI =& load_class('Input'); if ($CI->is_ajax_request() == true) { $run->pushHandler(new JsonResponseHandler()); } // Register the handler with PHP, and you're set! $run->register(); }
public function handle(Request $request, $statusCode) { $runner = new Run(); $format = $request->getRequestFormat(); if ('html' == $format) { $handler = new PrettyPageHandler(); $handler->addDataTable('App', ['Controller' => $request->get('_controller'), 'Route' => $request->get('_route'), 'Session' => $request->hasSession(), 'Status' => $this->getCodeWithDescription($statusCode)]); } else { if ('json' == $format) { $handler = new JsonResponseHandler(); } else { $handler = new PlainTextHandler(); } } $runner->pushHandler($handler); $runner->writeToOutput(false); $runner->allowQuit(false); $runner->register(); return $runner; }
/** * @param Exception|Throwable $exception * @param SapiInterface $sapi * @param ContainerInterface $container * * @SuppressWarnings(PHPMD.ElseExpression) */ private function handle($exception, SapiInterface $sapi, ContainerInterface $container) { $appConfig = $container->get(ConfigInterface::class)->getConfig(C::class); $message = 'Internal Server Error'; $this->logException($exception, $container, $message); if ($appConfig[C::KEY_IS_LOG_ENABLED] === true) { $run = new Run(); $handler = new PrettyPageHandler(); // You can add app specific detailed data here $appSpecificDetails = []; $appName = $appConfig[C::KEY_NAME]; if (empty($appSpecificDetails) === false) { $handler->addDataTable("{$appName} Details", $appSpecificDetails); } $handler->setPageTitle("Whoops! There was a problem with '{$appName}'."); $run->pushHandler($handler); $htmlMessage = $run->handleException($exception); $response = new HtmlResponse($htmlMessage, 500); } else { $response = new TextResponse($message, 500); } $sapi->handleResponse($response); }
/** * Constructor. * * @param array $configs * * @since 0.0.6 */ public function __construct($configs = []) { // Use Whoops vendor to display errors $run = new Run(); // New Pretty handler $handler = new PrettyPageHandler(); // Custom tables if (!empty($configs)) { $handler->addDataTable('Olympus configurations', $configs); } // Page title $handler->setPageTitle('Whoops! There was a problem.'); // Page custom CSS $handler->setResourcesPath(WEBPATH . 'resources' . S . 'whoops' . S); $handler->addCustomCss('olympoops.base.css'); // Push all in handler $run->pushHandler($handler); // AJAX requests if (Misc::isAjaxRequest()) { $run->pushHandler(new JsonResponseHandler()); } // Handler registration $run->register(); }
/** * Add a data table to whoops. * * @param string $label The data table name. * @param mixed $data The data to show. * * @return void */ public static function add($label, $data) { self::$handler->addDataTable($label . ':' . uniqid(), (array) $data); }
private function addRequestInfo(Request $request, PrettyPageHandler $handler) { $handler->addDataTable('Request', array('URI' => $request->getUri(), 'Request URI' => $request->getRequestUri(), 'Path Info' => $request->getPathInfo(), 'Query String' => $request->getQueryString() ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getScriptName(), 'Base Path' => $request->getBasePath(), 'Base URL' => $request->getBaseUrl(), 'Scheme' => $request->getScheme(), 'Port' => $request->getPort(), 'Host' => $request->getHost())); }
/** * Configure handler * Right now there are 2 handlers: onNotFound and onError * * @return void */ protected function configureHandler() { if ($this->config('_handlerConfigured') !== true) { $app = $this; if ($this->config('bono.cli') !== true) { $this->whoops = new Run(); $handler = new PrettyPageHandler(); $path = explode(DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, __DIR__); $path = $path[0] . '/templates/_whoops'; $handler->setResourcesPath($path); $jsonResponseHandler = new JsonResponseHandler(); $jsonResponseHandler->onlyForAjaxRequests(true); $appHandler = function ($err) use($app, $handler) { if (!isset($app->request)) { return; } $template = 'error.php'; if ($err->getMessage() === '404 Resource not found') { $template = 'notFound.php'; } $request = $app->request; // Add some custom tables with relevant info about your application, // that could prove useful in the error page: $handler->addDataTable('Bono Application', array('Template' => 'Modify this page on templates/' . $template, 'Application Class' => get_class($app), 'Charset' => $request->headers('ACCEPT_CHARSET') ?: '<none>', 'Locale' => $request->getContentCharset() ?: '<none>')); $handler->addDataTable('Bono Request', array('URI' => $request->getRootUri(), 'Request URI' => $request->getResourceUri(), 'Path' => $request->getPath(), 'Query String' => $request->params() ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getScriptName(), 'Base URL' => $request->getUrl(), 'Scheme' => $request->getScheme(), 'Port' => $request->getPort(), 'Host' => $request->getHost())); // Set the title of the error page: $handler->setPageTitle("Bono got whoops! There was a problem."); }; $this->whoops->pushHandler($handler); // Add a special handler to deal with AJAX requests with an // equally-informative JSON response. Since this handler is // first in the stack, it will be executed before the error // page handler, and will have a chance to decide if anything // needs to be done. $this->whoops->pushHandler($jsonResponseHandler); $this->whoops->pushHandler($appHandler); $this->notFound(array(new NotFoundHandler($this), 'handle')); $this->error(array(new ErrorHandler($this), 'handle')); } $this->config('_handlerConfigured', true); } return $this; }
/** * Genera una respuesta con el mensaje de error * * @param Peticion $peticion * @param int $estadoHttp * @param \Throwable $error * * @return Respuesta */ public function generarRespuestaError(Peticion $peticion, $estadoHttp = 500, $error = null) { ob_end_clean(); // Preparamos respuesta a arrojar $respuesta = new Respuesta(); if (isset($this->erroresHttp[$estadoHttp])) { $respuesta->definirContenido('<h1>' . $this->erroresHttp[$estadoHttp] . '</h1>'); } $respuesta->definirEstadoHttp($estadoHttp); // Mostramos el detalle del error si el ambiente es desarrollo if ('desarrollo' == $this->ambiente) { $whoops = new Run(); $whoops_pph = new PrettyPageHandler(); if (isset($error) && get_class($error) == 'Armazon\\Nucleo\\Excepcion' && $error->tieneDetalle()) { $whoops_pph->addDataTable('Información de Excepción:', (array) $error->obtenerDetalle()); } $whoops_pph->addDataTable('Petición:', (array) $peticion); $whoops->pushHandler($whoops_pph); $whoops->writeToOutput(false); $whoops->allowQuit(false); $respuesta->definirContenido($whoops->handleException($error)); return $respuesta; } // Buscamos estado en las rutas $ruta = $this->enrutador->buscar($peticion->metodo, $estadoHttp); // Cambiamos la respuesta despachando ruta en caso de ser encontrada if ('estado_http' != $ruta->tipo && 404 != $ruta->estadoHttp) { $respuesta = $this->despacharRuta($peticion, $ruta, $estadoHttp); } return $respuesta; }
* * Or just run it through apache/nginx/what-have-yous as usual. */ namespace Whoops\Example; use Whoops\Run; use Whoops\Handler\PrettyPageHandler; use Exception as BaseException; require __DIR__ . '/../vendor/autoload.php'; class Exception extends BaseException { } $run = new Run(); $handler = new PrettyPageHandler(); // Add a custom table to the layout: $handler->addDataTable('Ice-cream I like', array('Chocolate' => 'yes', 'Coffee & chocolate' => 'a lot', 'Strawberry & chocolate' => 'it\'s alright', 'Vanilla' => 'ew')); $run->pushHandler($handler); // Example: tag all frames inside a function with their function name $run->pushHandler(function ($exception, $inspector, $run) { $inspector->getFrames()->map(function ($frame) { if ($function = $frame->getFunction()) { $frame->addComment("This frame is within function '{$function}'", 'cpt-obvious'); } return $frame; }); }); $run->register(); function fooBar() { throw new Exception("Something broke!"); }
/** * Installs whoops exception handler. * * @author Benjamin Carl <*****@*****.**> * @return $this Instance for chaining * @access protected */ protected function installWhoops() { // Configure the page handler of Whoops if (true === $this->isCli()) { // Text for cli $exceptionHandler = new PlainTextHandler(); } else { // Otherwise the pretty one $exceptionHandler = new PrettyPageHandler(); $constants = get_defined_constants(); $exceptionHandler->setPageTitle('Doozr'); // Extract Doozr Constants as debugging information $data = []; foreach ($constants as $key => $value) { if ('DOOZR_' === substr($key, 0, 6)) { $data[$key] = true === is_bool($value) ? true === $value ? 'TRUE' : 'FALSE' : $value; } } ksort($data); $exceptionHandler->addDataTable('Doozr Environment', $data); } $this->getWhoops()->pushHandler($exceptionHandler); $this->getWhoops()->register(); // Chaining return $this; }
/** * Prepare the Whoops page handler with a table displaying request information * * @param Request $request * @param PrettyPageHandler $handler */ private function prepareWhoopsHandler(Request $request, PrettyPageHandler $handler) { $uri = $request->getAttribute('originalUri', false) ?: $request->getUri(); $request = $request->getAttribute('originalRequest', false) ?: $request; $handler->addDataTable('Expressive Application Request', ['HTTP Method' => $request->getMethod(), 'URI' => (string) $uri, 'Script' => $request->getServerParams()['SCRIPT_NAME'], 'Headers' => $request->getHeaders(), 'Cookies' => $request->getCookieParams(), 'Attributes' => $request->getAttributes(), 'Query String Arguments' => $request->getQueryParams(), 'Body Params' => $request->getParsedBody()]); }
<?php use Lucid\Lucid; Lucid::$app['config']['factory/sendE3rrors'] = function ($errorList) { Lucid::$app->logger()->warning('successfully called sendErrors hook!'); }; use Whoops\Handler\PrettyPageHandler; use Whoops\Handler\JsonResponseHandler; use Whoops\Handler\Handler; $run = new Whoops\Run(); $handler = new PrettyPageHandler(); // Add some custom tables with relevant info about your application, // that could prove useful in the error page: $handler->addDataTable('Killer App Details', array("Important Data" => 'some data', "Thingamajig-id" => 'some id')); // Set the title of the error page: $handler->setPageTitle("Whoops! There was a problem."); $run->popHandler(); // Add a special handler to deal with AJAX requests with an // equally-informative JSON response. Since this handler is // first in the stack, it will be executed before the error // page handler, and will have a chance to decide if anything // needs to be done. $run->pushHandler(function ($exception, $inspector, $run) { Lucid::$app->response()->message($exception->getMessage()); Lucid::$app->response()->write('error'); #var_dump($exception->getMessage()); return Handler::DONE; }); #$run->pushHandler(new JsonResponseHandler); // Register the handler with PHP, and you're set! $run->register();