Пример #1
0
 /**
  * registerWhoops
  *
  * @return void
  */
 public static function registerWhoops()
 {
     self::$whoops = new Run();
     self::$handler = new PrettyPageHandler();
     self::$whoops->pushHandler(self::$handler);
     self::$whoops->register();
 }
Пример #2
0
 public function register()
 {
     $error_page = new PrettyPageHandler();
     $error_page->setEditor('sublime');
     $this->whoops->pushHandler($error_page);
     $this->whoops->register();
 }
Пример #3
0
 /**
  * Registers the instance as a debugger.
  *
  * @return \Whoops\Run
  */
 public function display()
 {
     error_reporting(E_ALL);
     if ($this->environment === 'development') {
         $this->setHandler(new \Whoops\Handler\PrettyPageHandler());
     }
     return $this->whoops->register();
 }
 /**
  * Class constructor
  *
  * @param integer $iDebug debug level
  */
 public function __construct($iDebug = 0)
 {
     parent::__construct($iDebug);
     if ($this->showExtendedExceptionInfo()) {
         $this->whoops = new Whoops\Run();
         $this->whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
         $this->whoops->register();
     }
 }
Пример #5
0
 /**
  * 激活调试器
  */
 public static function enable()
 {
     if (self::$enabled) {
         return;
     }
     self::$_debugger = new Run();
     self::$_debugger->pushHandler(new PrettyPageHandler());
     self::$_debugger->register();
     self::$enabled = true;
 }
Пример #6
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'));
 }
Пример #7
0
 /**
  * Handle errors thrown in the application.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $hasUser = $this->session->isStarted() && $this->session->has('authentication');
     if (!$hasUser && !$this->showWhileLoggedOff) {
         return;
     }
     // Register Whoops as an error handler
     $this->whoops->register();
     $exception = $event->getException();
     ob_start();
     $this->whoops->handleException($exception);
     $response = ob_get_clean();
     $code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR;
     $event->setResponse(new Response($response, $code));
 }
Пример #8
0
 public function onBootstrap(EventInterface $e)
 {
     $this->serviceLocator = $e->getTarget()->getServiceManager();
     $config = $e->getTarget()->getServiceManager()->get('Config');
     $this->whoopsConfig = $config['arilas']['whoops'];
     if ($this->whoopsConfig['disabled']) {
         return;
     }
     $this->run = new Run();
     $this->run->register();
     $this->run->pushHandler($this->getHandler());
     $eventManager = $e->getTarget()->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareException'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareException'));
 }
Пример #9
0
 public function register(ContainerInterface $app)
 {
     $whoops = new Whoops();
     $whoops->pushHandler(new PrettyPageHandler());
     $whoops->register();
     $app->instance(Whoops::class, $whoops);
 }
Пример #10
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;
         }
     }
 }
Пример #11
0
 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);
 }
Пример #12
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);
 }
 protected function registerErrorHandler()
 {
     $run = new WhoopsRun();
     $handler = new PrettyPageHandler();
     $run->pushHandler($handler);
     $run->register();
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     //
     $whoops = new Run();
     $whoops->pushHandler(new PrettyPageHandler());
     $whoops->register();
 }
Пример #15
0
 /**
  * Saving Application instance for later use
  *
  * @param Container $container
  * @return void
  */
 public function provideServices(Container $container)
 {
     $this->container = $container;
     /*
      * Creating and registering our error handler
      */
     $whoops = new Run();
     $whoops->register();
     /** @var \Venta\Contracts\Kernel\Kernel $kernel */
     $kernel = $container->get(Kernel::class);
     if ($kernel->isCli()) {
         // We don't need pretty pages in cli mode
         $whoops->allowQuit(true);
         $whoops->sendHttpCode(false);
         $whoops->writeToOutput(true);
         $whoops->pushHandler(new PlainTextHandler());
     } else {
         // Push pretty page handler only for local environment
         $whoops->pushHandler($kernel->getEnvironment() === 'local' ? new PrettyPageHandler() : new PlainTextHandler());
     }
     /**
      * Bind error handler
      */
     $container->bindClass(RunInterface::class, $whoops, ['error_handler']);
     /*
      * Bind PSR-3 logger
      */
     $container->share(\Monolog\Logger::class, function (Container $c) {
         $logger = new \Monolog\Logger('venta');
         $handler = new \Monolog\Handler\StreamHandler(__DIR__ . '/../storage/logs/app.log');
         $handler->pushProcessor(function ($record) use($c) {
             /** @var \Venta\Contracts\Kernel\Kernel $kernel */
             $kernel = $c->get(Kernel::class);
             if ($kernel->isCli()) {
                 // Add cli command related extra info
                 /** @var \Symfony\Component\Console\Input\InputInterface $input */
                 $input = $c->get(InputInterface::class);
                 $record['extra']['command'] = $input->getFirstArgument();
                 $record['extra']['arguments'] = $input->getArguments();
                 $record['extra']['options'] = $input->getOptions();
             } else {
                 // Add HTTP request related extra info
                 /** @var \Psr\Http\Message\ServerRequestInterface $request */
                 $request = $c->get(ServerRequestInterface::class);
                 $server = $request->getServerParams();
                 $record['extra']['url'] = $request->getUri()->getPath();
                 $record['extra']['http_method'] = $request->getMethod();
                 $record['extra']['host'] = $request->getUri()->getHost();
                 $record['extra']['referer'] = $request->getHeader('referer');
                 $record['extra']['user_agent'] = $request->getHeader('user-agent');
                 $record['extra']['ip'] = $server['REMOTE_ADDR'] ?? null;
             }
             return $record;
         });
         $handler->setFormatter(new \Monolog\Formatter\LineFormatter());
         $logger->pushHandler($handler);
         return $logger;
     }, ['logger', LoggerInterface::class]);
 }
Пример #16
0
 private function registerWhoops()
 {
     // Register whoops
     $whoops = new Whoops();
     $ph = new PrettyPageHandler();
     $whoops->pushHandler($ph);
     $whoops->register();
 }
Пример #17
0
 public function setErrorTraits($traits)
 {
     $run = new Run();
     $handler = new PrettyPageHandler();
     $handler->addDataTable('Traits', $traits);
     $run->pushHandler($handler);
     $run->register();
 }
Пример #18
0
 /**
  * Register the Whoops error display service.
  *
  * @return void
  */
 protected function registerWhoops()
 {
     // We will instruct Whoops to not exit after it displays the exception as it
     // will otherwise run out before we can do anything else. We just want to
     // let the framework go ahead and finish a request on this end instead.
     with($whoops = new Run())->allowQuit(false);
     $whoops->pushHandler($this->app['whoops.handler']);
     $whoops->register();
 }
 public function register()
 {
     $this->app->singleton('errorsStyle', function () {
         $errorsStyle = new Run();
         $errorsStyle->pushHandler(new PrettyPageHandler());
         $errorsStyle->register();
         return $errorsStyle;
     });
 }
Пример #20
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();
 }
Пример #21
0
 /**
  * Create a Symfony response for the given exception.
  *
  * @param  \Exception  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function convertExceptionToResponse(Exception $e)
 {
     if (config('app.debug')) {
         $whoops = new Whoops();
         $whoops->pushHandler(new PrettyPage());
         $whoops->register();
         return SymfonyResponse::create($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
     }
     return parent::convertExceptionToResponse($e);
 }
Пример #22
0
 public static function register(Application $app)
 {
     $whoops = new Run();
     if (ConfigManager::exists('app.display_errors') && ConfigManager::get('app.display_errors')) {
         $whoops->pushHandler(new PrettyPageHandler());
     } else {
         $whoops->pushHandler(new ProdHandler($app));
     }
     $whoops->register();
 }
Пример #23
0
 /**
  * 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;
 }
 public function loadDebug()
 {
     if (empty($this->modeDebug)) {
         ini_set("display_errors", false);
         return;
     }
     $whoops = new Run();
     $whoops->pushHandler(new PrettyPageHandler());
     $whoops->register();
 }
 /**
  * @param string         $message
  * @param int            $code
  * @param Exception|null $previous
  */
 public function __construct($message = "", $code = 0, Exception $previous = null)
 {
     parent::__construct($message, $code, $previous);
     if (WP_DEBUG && WP_DEBUG_DISPLAY) {
         $run = new Run();
         $handler = new PrettyPageHandler();
         $run->pushHandler($handler);
         $run->register();
     }
 }
Пример #26
0
 public function __construct($pretty = true)
 {
     $run = new Run();
     if ($pretty) {
         $handler = new PrettyPageHandler();
     } else {
         $handler = new JsonResponseHandler();
     }
     $run->pushHandler($handler);
     $run->register();
 }
Пример #27
0
 public static function initialize()
 {
     $run = new Run();
     if (\BWBlog\Utils::isAjax()) {
         $handler = new JsonResponseHandler();
     } else {
         $handler = new PrettyPageHandler();
     }
     $run->pushHandler($handler);
     $run->register();
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 public function __invoke($error, Request $request, Response $response, callable $out = null)
 {
     $whoops = new Run();
     $whoops->pushHandler(new PrettyPageHandler());
     $whoops->register();
     $method = Run::EXCEPTION_HANDLER;
     ob_start();
     $whoops->{$method}($error);
     $response = ob_get_clean();
     return StringResponse::html($response, 500);
 }
Пример #29
0
 public static function handle($error)
 {
     $whoops = new Run();
     $whoops->pushHandler(new PrettyPageHandler());
     $whoops->register();
     $method = Run::EXCEPTION_HANDLER;
     ob_start();
     $whoops->{$method}($error);
     $response = ob_get_clean();
     return StringResponse::html($response, 500);
 }
Пример #30
0
 /**
  * Register error handler.
  */
 public function registerErrorHandler()
 {
     $environment = getenv('ENVIRONMENT');
     $whoops = new Whoops();
     if ($environment !== 'production') {
         $whoops->pushHandler(new PrettyPageHandler());
     } else {
         // @todo: This should display a pretty error page instead.
         $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
     }
     $whoops->register();
 }