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; }
/** * Instantiate Whoops with the correct handlers. */ public function init() { parent::init(); require 'YiiWhoopsRunner.php'; $this->whoops = new YiiWhoopsRunner(); if (Yii::app()->request->isAjaxRequest) { $this->whoops->pushHandler(new JsonResponseHandler()); } else { $page_handler = new PrettyPageHandler(); if (isset($this->pageTitle)) { $page_handler->setPageTitle($this->pageTitle); } if (isset($this->editor)) { $editor = $this->editor; switch ($editor) { case 'sublime': case 'emacs': case 'textmate': case 'macvim': case 'xdebug': $page_handler->setEditor($editor); break; default: $page_handler->setEditor(function ($file, $line) use($editor) { return strtr($editor, array('{file}' => $file, '{line}' => $line)); }); break; } } $this->whoops->pushHandler($page_handler); } }
/** * 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 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(); }
public function register(Application $app) { $whoops = new \Whoops\Run(); $whoops->allowQuit(false); $handler = new \Whoops\Handler\PrettyPageHandler(); $handler->setPageTitle("Whoops! There was a problem."); $whoops->pushHandler($handler); $whoops->register(); $app->set('Whoops', $whoops); }
private function boot() { if (ENVIRONMENT == 'development') { $run = new \Whoops\Run(); $handler = new PrettyPageHandler(); $handler->setPageTitle("We're all going to be fired!"); $handler->setEditor('textmate'); $run->pushHandler($handler); $handler = new JsonResponseHandler(); $handler->onlyForAjaxRequests(true); $run->pushHandler($handler); $run->register(); } }
public static function run() { //初始化session session_start(); //初始化配置文件 Config::getInstance(); $appConfig = Config::get('app'); //初始化主题 $public = $appConfig['public'] ? $appConfig['public'] : 'public'; Filesystem::mkdir($public, 444); if (!empty($appConfig['theme'])) { defined("APP_THEME") or define("APP_THEME", $public . '/' . $appConfig['theme']); } else { defined("APP_THEME") or define("APP_THEME", $public); } //初始化应用名字 if (!empty($appConfig['name'])) { defined("APP_NAME") or define("APP_NAME", $appConfig['name']); } else { defined("APP_NAME") or define("APP_NAME", 'Simpla'); } //初始化应用URL域名 defined("BASE_URL") or define("BASE_URL", $appConfig['url']); //是否开启错误提示 if ($appConfig['debug'] == 1) { error_reporting(E_ALL); } else { error_reporting(0); } //初始化数据库 Model::getInstance(); //初始化缓存 ICache::getInstance(); Cache::getInstance(); //初始化whoops $run = new \Whoops\Run(); $handler = new PrettyPageHandler(); // 设置错误页面的标题 $handler->setPageTitle("Whoops! 出现了一个错误."); $run->pushHandler($handler); //设置ajax错误提示. if (\Whoops\Util\Misc::isAjaxRequest()) { $run->pushHandler(new JsonResponseHandler()); } // 注册handler $run->register(); //路由处理 Route::check(); }
public function __construct() { // Load in whoops on exception? $this->whoops = Configuration::get('app.env', 'production') === 'development' && Configuration::get('app.visualException', false); if ($this->whoops) { $this->whoops = new Run(); $pretty = new PrettyPageHandler(); $pretty->setPageTitle("Arvici - Exception is thrown!"); if (Configuration::get('app.ide', 'none') === 'idea') { $pretty->setEditor(function ($file, $line) { return array('url' => "http://localhost:63342/api/file/?file={$file}&line={$line}", 'ajax' => true); }); } $this->whoops->pushHandler($pretty); } }
public function register(Container $app) { if (!$app['config']->get('app.debug')) { return false; } $run = new Run(); $handler = new PrettyPageHandler(); // Set the title of the error page: $handler->setPageTitle('Whoops! There was a problem.'); $run->pushHandler($handler); if (Misc::isAjaxRequest() || $app['is_api_request']) { $run->pushHandler(new JsonResponseHandler()); } // Register the handler with PHP, and you're set! $run->register(); }
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(); }
/** * {@inheritdoc} */ public function register(Application $app) { $app['whoops'] = $app->share(function () use($app) { $run = new Run(); $run->allowQuit(false); $run->pushHandler($app['whoops.handler']); return $run; }); $app['whoops.handler'] = $app->share(function () use($app) { if (PHP_SAPI === 'cli') { return $app['whoops.handler.cli']; } else { return $app['whoops.handler.page']; } }); $app['whoops.handler.cli'] = $app->share(function () { return new PlainTextHandler(); }); $app['whoops.handler.page'] = $app->share(function () use($app) { $handler = new PrettyPageHandler(); $handler->addDataTableCallback('Bolt Application', $app['whoops.handler.page.app_info']); $handler->addDataTableCallback('Request', $app['whoops.handler.page.request_info']); $handler->setPageTitle('Bolt - Fatal error.'); return $handler; }); $app['whoops.handler.page.app_info'] = $app->protect(function () use($app) { return ['Charset' => $app['charset'], 'Locale' => $app['locale'], 'Route Class' => $app['route_class'], 'Dispatcher Class' => $app['dispatcher_class'], 'Application Class' => get_class($app)]; }); $app['whoops.handler.page.request_info'] = $app->protect(function () use($app) { /** @var RequestStack $requestStack */ $requestStack = $app['request_stack']; if (!($request = $requestStack->getCurrentRequest())) { return []; } return ['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()]; }); $app['whoops.listener'] = $app->share(function () use($app) { $showWhileLoggedOff = $app['config']->get('general/debug_show_loggedoff', false); return new WhoopsListener($app['whoops'], $app['session'], $showWhileLoggedOff); }); }
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(); }
/** * @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); }
public function init() { $whoops = new \Whoops\Run(); $errorPage = new Whoops\Handler\PrettyPageHandler(); $errorPage->setPageTitle('Oops! There was an error...'); $whoops->pushHandler($errorPage); if (function_exists('Whoops\\isAjaxRequest')) { if (Whoops\isAjaxRequest()) { $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } } else { $jsonPage = new Whoops\Handler\JsonResponseHandler(); $jsonPage->onlyForAjaxRequests(true); } $whoops->pushHandler(function ($exception, $inspector, $run) { try { logg($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString(), 'critical'); } catch (\Exception $e) { echo $e; } }, 'log'); $whoops->register(); }
/** * 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(); }
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; }
/** * 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; }
/** * 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; }
$webroot_path = $root_path . DS . 'htdocs'; /*----------------------------------------------------*/ // Include composer autoloading /*----------------------------------------------------*/ if (file_exists($autoload = $root_path . DS . 'vendor' . DS . 'autoload.php')) { require_once $autoload; } /*----------------------------------------------------*/ // Load Whoops /*-----------------------------------------------------*/ use Whoops\Handler\PrettyPageHandler; use Whoops\Handler\JsonResponseHandler; $run = new Whoops\Run(); $handler = new PrettyPageHandler(); // Set the title of the error page: $handler->setPageTitle("Whoops! There was a problem."); $run->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. if (Whoops\Util\Misc::isAjaxRequest()) { $run->pushHandler(new JsonResponseHandler()); } // Register the handler with PHP, and you're set! $run->register(); /*----------------------------------------------------*/ // Load environment configuration /*----------------------------------------------------*/ $environments = [];