Inheritance: extends Whoops\Handler\Handler
 public function register()
 {
     $error_page = new PrettyPageHandler();
     $error_page->setEditor('sublime');
     $this->whoops->pushHandler($error_page);
     $this->whoops->register();
 }
Example #2
0
 /**
  * Convert the view to a rendered string.
  *
  * @return string A string of HTML, e.g. to be `echo`'d.
  */
 public function __toString()
 {
     static $run, $handler;
     if (!isset($run, $handler)) {
         $run = new Run();
         $handler = new PrettyPageHandler();
         $handler->handleUnconditionally(true);
         $run->pushHandler($handler);
         $run->allowQuit(false);
         $run->writeToOutput(false);
         $run->register();
     }
     // __toString cannot throw an exception, so we need to handle those
     // manually to prevent PHP from barfing:
     try {
         return $this->render();
     } catch (Exception $e) {
         self::$didWhoops = true;
         if (!static::$swallowError) {
             return $run->handleException($e);
         } else {
             return static::$swallowError;
         }
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
     }
 }
Example #5
0
 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()]);
 }
Example #7
0
 public function setErrorTraits($traits)
 {
     $run = new Run();
     $handler = new PrettyPageHandler();
     $handler->addDataTable('Traits', $traits);
     $run->pushHandler($handler);
     $run->register();
 }
Example #8
0
 public function handle(\Throwable $throwable)
 {
     // echo '1';
     $pretty = new PrettyPageHandler();
     $pretty->setException($throwable);
     $pretty->setInspector(new Inspector($throwable));
     $pretty->handle();
 }
Example #9
0
 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;
 }
Example #11
0
 public static function stop($name = "User Debug", $array_vars = array())
 {
     if (is_array($name)) {
         $array_vars = $name;
         $name = "User Debug";
     }
     //
     $Handler = new PrettyPageHandler();
     $Handler->handleUserDebug($name, $array_vars);
 }
Example #12
0
 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);
 }
Example #13
0
 public function onBootstrap(EventInterface $event)
 {
     $prettyPageHandler = new PrettyPageHandler();
     // Set editor
     $config = $event->getApplication()->getServiceManager()->get('Config');
     if (isset($config['view_manager']['editor'])) {
         $prettyPageHandler->setEditor($config['view_manager']['editor']);
     }
     $this->run = new Run();
     $this->run->register();
     $this->run->pushHandler($prettyPageHandler);
     $this->attachListeners($event);
 }
Example #14
0
 /**
  * @param array $values Optional arguments for container.
  */
 public function __construct($values = array())
 {
     $defaults = array();
     $defaults['tables'] = array('$wp' => function () {
         global $wp;
         if (!$wp instanceof \WP) {
             return array();
         }
         $output = get_object_vars($wp);
         unset($output['private_query_vars']);
         unset($output['public_query_vars']);
         return array_filter($output);
     }, '$wp_query' => function () {
         global $wp_query;
         if (!$wp_query instanceof \WP_Query) {
             return array();
         }
         $output = get_object_vars($wp_query);
         $output['query_vars'] = array_filter($output['query_vars']);
         unset($output['posts']);
         unset($output['post']);
         return array_filter($output);
     }, '$post' => function () {
         $post = get_post();
         if (!$post instanceof \WP_Post) {
             return array();
         }
         return get_object_vars($post);
     });
     $defaults['handler.pretty'] = function ($plugin) {
         $handler = new PrettyPageHandler();
         foreach ($plugin['tables'] as $name => $callback) {
             $handler->addDataTableCallback($name, $callback);
         }
         // Requires Remote Call plugin.
         $handler->addEditor('phpstorm-remote-call', 'http://localhost:8091?message=%file:%line');
         return $handler;
     };
     $defaults['handler.json'] = function () {
         $handler = new Admin_Ajax_Handler();
         $handler->addTraceToOutput(true);
         return $handler;
     };
     $defaults['run'] = function ($plugin) {
         $run = new Run();
         $run->pushHandler($plugin['handler.pretty']);
         $run->pushHandler($plugin['handler.json']);
         return $run;
     };
     parent::__construct(array_merge($defaults, $values));
 }
Example #15
0
 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();
     }
 }
Example #16
0
 /**
  * {@inheritDoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     $config = $e->getTarget()->getServiceManager()->get('Config');
     $config = isset($config['view_manager']) ? $config['view_manager'] : array();
     if ($e->getRequest() instanceof ConsoleRequest || empty($config['display_exceptions'])) {
         return;
     }
     $this->run = new Run();
     $this->run->register();
     // set up whoops config
     $prettyPageHandler = new PrettyPageHandler();
     if (isset($config['editor'])) {
         if ($config['editor'] == 'phpStorm') {
             $localPath = null;
             if (isset($config['local_path'])) {
                 $localPath = $config['local_path'];
             }
             $prettyPageHandler->setEditor(function ($file, $line) use($localPath) {
                 if ($localPath) {
                     // if your development server is not local it's good to map remote files to local
                     $translations = array('^' . __DIR__ => $config['editor_path']);
                     // change to your path
                     foreach ($translations as $from => $to) {
                         $file = preg_replace('#' . $from . '#', $to, $file, 1);
                     }
                 }
                 return "pstorm://{$file}:{$line}";
             });
         } else {
             $prettyPageHandler->setEditor($config['editor']);
         }
     }
     if (!empty($config['json_exceptions']['display'])) {
         $jsonHandler = new JsonResponseHandler();
         if (!empty($config['json_exceptions']['show_trace'])) {
             $jsonHandler->addTraceToOutput(true);
         }
         if (!empty($config['json_exceptions']['ajax_only'])) {
             $jsonHandler->onlyForAjaxRequests(true);
         }
         $this->run->pushHandler($jsonHandler);
     }
     if (!empty($config['whoops_no_catch'])) {
         $this->noCatchExceptions = $config['whoops_no_catch'];
     }
     $this->run->pushHandler($prettyPageHandler);
     $eventManager = $e->getTarget()->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareException'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareException'));
 }
Example #17
0
 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 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();
 }
Example #19
0
 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);
     }
 }
Example #20
0
 /**
  * {@inheritDoc}
  */
 public function handle()
 {
     $this->setPageTitle("concrete5 has encountered an issue.");
     $result = self::QUIT;
     $enabled = Config::get('concrete.debug.display_errors');
     if ($enabled) {
         $detail = Config::get('concrete.debug.detail', 'message');
         if ($detail === 'debug') {
             $this->addDetails();
             $result = parent::handle();
         } else {
             $e = $this->getInspector()->getException();
             Core::make('helper/concrete/ui')->renderError(t('An unexpected error occurred.'), h($e->getMessage()));
         }
     } else {
         Core::make('helper/concrete/ui')->renderError(t('An unexpected error occurred.'), t('An error occurred while processing this request.'));
     }
     if (Config::get('concrete.log.errors')) {
         try {
             $e = $this->getInspector()->getException();
             $db = Database::get();
             if ($db->isConnected()) {
                 $l = new Logger(LOG_TYPE_EXCEPTIONS);
                 $l->emergency(sprintf("Exception Occurred: %s:%d %s (%d)\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode()), array($e));
             }
         } catch (\Exception $e) {
         }
     }
     return $result;
 }
Example #21
0
 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);
 }
 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);
 }
 /**
  * Inject an editor into the whoops configuration.
  *
  * @see https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md
  * @param PrettyPageHandler $handler
  * @param array|\ArrayAccess $config
  * @param ContainerInterface $container
  * @throws Exception\InvalidServiceException for an invalid editor definition.
  */
 private function injectEditor(PrettyPageHandler $handler, $config, ContainerInterface $container)
 {
     if (!isset($config['editor'])) {
         return;
     }
     $editor = $config['editor'];
     if (is_callable($editor)) {
         $handler->setEditor($editor);
         return;
     }
     if (!is_string($editor)) {
         throw new Exception\InvalidServiceException(sprintf('Whoops editor must be a string editor name, string service name, or callable; received "%s"', is_object($editor) ? get_class($editor) : gettype($editor)));
     }
     if ($container->has($editor)) {
         $editor = $container->get($editor);
     }
     $handler->setEditor($editor);
 }
Example #24
0
 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();
 }
Example #25
0
 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;
 }
Example #26
0
 /**
  * {@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);
     });
 }
Example #27
0
 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();
     }
 }
Example #28
0
 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 __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 register(Container $container)
 {
     /** @var $config Registry */
     $config = $container->resolve('config');
     if ($config->get('debug', false)) {
         $whoops = new Run();
         $handler = new PrettyPageHandler();
         $editor = $config->get('debugEditor');
         if ($editor == 'pstorm') {
             $handler->setEditor(function ($file, $line) {
                 return "pstorm://{$file}:{$line}";
             });
         } else {
             $handler->setEditor($editor);
         }
         $whoops->pushHandler($handler);
         $whoops->register();
         $container->bind('whoops', function () use($whoops) {
             return $whoops;
         });
     }
 }