public function register(Container $container) { // Setup Whoops-based error handler $errors = new Errors(); $error_page = new PrettyPageHandler(); $error_page->setPageTitle('Crikey! There was an error...'); $error_page->setEditor('sublime'); $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); $error_page->addCustomCss('whoops.css'); $json_page = new JsonResponseHandler(); $json_page->onlyForAjaxRequests(true); $errors->pushHandler($error_page, 'pretty'); $errors->pushHandler(new PlainTextHandler(), 'text'); $errors->pushHandler($json_page, 'json'); $logger = $container['log']; $errors->pushHandler(function (\Exception $exception, $inspector, $run) use($logger) { try { $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString()); } catch (\Exception $e) { echo $e; } }, 'log'); $errors->register(); $container['errors'] = $errors; }
public function resetHandlers() { $grav = Grav::instance(); $config = $grav['config']->get('system.errors'); $jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json'; // Setup Whoops-based error handler $whoops = new \Whoops\Run(); $verbosity = 1; if (isset($config['display'])) { if (is_int($config['display'])) { $verbosity = $config['display']; } else { $verbosity = $config['display'] ? 1 : 0; } } switch ($verbosity) { case 1: $error_page = new Whoops\Handler\PrettyPageHandler(); $error_page->setPageTitle('Crikey! There was an error...'); $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); $error_page->addCustomCss('whoops.css'); $whoops->pushHandler($error_page); break; case -1: $whoops->pushHandler(new BareHandler()); break; default: $whoops->pushHandler(new SimplePageHandler()); break; } if (method_exists('Whoops\\Util\\Misc', 'isAjaxRequest')) { //Whoops 2.0 if (Whoops\Util\Misc::isAjaxRequest() || $jsonRequest) { $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } } elseif (function_exists('Whoops\\isAjaxRequest')) { //Whoops 2.0.0-alpha if (Whoops\isAjaxRequest() || $jsonRequest) { $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } } else { //Whoops 1.x $json_page = new Whoops\Handler\JsonResponseHandler(); $json_page->onlyForAjaxRequests(true); } if (isset($config['log']) && $config['log']) { $logger = $grav['log']; $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { try { $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString()); } catch (\Exception $e) { echo $e; } }, 'log'); } $whoops->register(); }
/** * Register the Whoops! Exception Handler * * @return \Whoops\Run $whoops */ public function start() { $whoops = new Run(); $handler = new PrettyPageHandler(); $handler->addResourcePath(__DIR__ . '/Resources'); $handler->setEditor('sublime'); $whoops->pushHandler($handler); $whoops->register(); $this->whoops = $whoops; }
protected function configureErrorHandler() { if (!$this->isCli()) { $whoops = new WhoopsRun(); $handler = new PrettyPageHandler(); $handler->addResourcePath(__DIR__ . '/../../templates/vendor/whoops'); $whoops->pushHandler($handler); $whoops->pushHandler(function () use($handler) { $obs = []; while (ob_get_level() > 0) { $ob = trim(ob_get_contents()); if ($ob) { $obs[] = $ob; } ob_end_clean(); } $handler->addDataTable('Output Buffers', $obs); }); $whoops->register(); } }
public function resetHandlers() { $grav = Grav::instance(); $config = $grav['config']->get('system.errors'); // Setup Whoops-based error handler $whoops = new \Whoops\Run(); if (isset($config['display'])) { if ($config['display']) { $error_page = new Whoops\Handler\PrettyPageHandler(); $error_page->setPageTitle('Crikey! There was an error...'); $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); $error_page->addCustomCss('whoops.css'); $whoops->pushHandler($error_page); } else { $whoops->pushHandler(new SimplePageHandler()); } } if (function_exists('Whoops\\isAjaxRequest')) { //Whoops 2 if (Whoops\isAjaxRequest()) { $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } } else { //Whoops 1 $json_page = new Whoops\Handler\JsonResponseHandler(); $json_page->onlyForAjaxRequests(true); } if (isset($config['log']) && $config['log']) { $logger = $grav['log']; $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { try { $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString()); } catch (\Exception $e) { echo $e; } }, 'log'); } $whoops->register(); }
public function register(Container $container) { /** @var UniformResourceLocator $locator */ $locator = $container['locator']; /** @var Platform $platform */ $platform = $container['platform']; // Setup Whoops-based error handler $errors = new Run(); $errors->registerPaths($platform->errorHandlerPaths()); $error_page = new PrettyPageHandler(); $error_page->setPageTitle('Crikey! There was an error...'); $error_page->setEditor('sublime'); foreach ($locator->findResources('gantry-assets://css/whoops.css') as $path) { $error_page->addResourcePath(dirname($path)); } $error_page->addCustomCss('whoops.css'); $json_page = new JsonResponseHandler(); $json_page->onlyForAjaxRequests(true); $errors->pushHandler($error_page, 'pretty'); $errors->pushHandler(new PlainTextHandler(), 'text'); $errors->pushHandler($json_page, 'json'); $errors->register(); $container['errors'] = $errors; }
/** * Register the "pretty" Whoops handler. * * @return void */ protected function registerPrettyWhoopsHandler() { $this->app['whoops.handler'] = $this->app->share(function () { with($handler = new PrettyPageHandler())->setEditor('sublime'); // If the resource path exists, we will register the resource path with Whoops // so our custom Laravel branded exception pages will be used when they are // displayed back to the developer. Otherwise, the default pages are run. if (!is_null($path = $this->resourcePath())) { $handler->addResourcePath($path); } return $handler; }); }