コード例 #1
0
ファイル: WhoopsFormatter.php プロジェクト: Mosaic/Mosaic
 /**
  * @param Run $whoops
  */
 public function __construct(Run $whoops)
 {
     $this->whoops = $whoops;
     $this->whoops->allowQuit(false);
     $this->whoops->writeToOutput(false);
     $this->whoops->pushHandler(new PrettyPageHandler());
 }
コード例 #2
0
ファイル: WhoopsListener.php プロジェクト: thinframe/karma
 /**
  * Handle http exceptions
  *
  * @param UnknownHttpExceptionEvent $event
  */
 public function onException(UnknownHttpExceptionEvent $event)
 {
     if (!$this->environment->equals(Environment::DEVELOPMENT)) {
         return;
     }
     $event->stopPropagation();
     $this->whoops->writeToOutput(false);
     $this->whoops->allowQuit(false);
     $content = $this->whoops->handleException($event->getHttpException());
     $event->getResponse()->setContent($content);
 }
コード例 #3
0
ファイル: View.php プロジェクト: monomelodies/improse
 /**
  * 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;
         }
     }
 }
コード例 #4
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]);
 }
コード例 #5
0
ファイル: DebugDisplayer.php プロジェクト: ssomenzi/silence
 /**
  * Get the whoops instance.
  *
  * @return \Whoops\Run
  */
 protected function whoops()
 {
     $whoops = new Whoops();
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     $whoops->pushHandler(new Handler());
     return $whoops;
 }
コード例 #6
0
 /**
  * Returns the whoops instance.
  *
  * @return Whoops
  */
 private function getWhoops()
 {
     $whoops = new Whoops();
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     $whoops->pushHandler(new PrettyPageHandler());
     return $whoops;
 }
コード例 #7
0
 protected function handleWithWhoops(Exception $exception)
 {
     $whoops = new Run();
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     $whoops->pushHandler(new PrettyPageHandler());
     return $whoops->handleException($exception);
 }
コード例 #8
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new Whoops\Run();
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
     return response($whoops->handleException($e), 500);
 }
コード例 #9
0
 private function registerWhoops(Container $container)
 {
     $container['whoops'] = function (Container $container) {
         $run = new Run();
         $run->allowQuit(false);
         $run->pushHandler($container['whoops.error_page_handler']);
         return $run;
     };
 }
コード例 #10
0
 /**
  * @param ContainerInterface $application
  * @throws \InvalidArgumentException
  */
 public function register(ContainerInterface $application)
 {
     $this->app = $application;
     /**
      * register whoops when debug mode enabled
      */
     $this->app->singleton([ErrorHandler::class => 'ErrorHandler'], function () {
         if ($this->errorHandler instanceof PrettyPageHandler) {
             $this->errorHandler->handleUnconditionally(true);
         }
         $this->whoops = new Run();
         $this->whoops->allowQuit(false);
         $this->whoops->pushHandler($this->errorHandler);
         return new ErrorHandler($this->app, $this->whoops, $this->contentType);
     });
     /**
      * catch fatal error
      */
     register_shutdown_function([$this->app['ErrorHandler'], 'handleError']);
 }
コード例 #11
0
 /**
  * Create and return an instance of the Whoops runner.
  *
  * @param ContainerInterface $container
  * @return Whoops
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     $config = isset($config['whoops']) ? $config['whoops'] : [];
     $whoops = new Whoops();
     $whoops->writeToOutput(false);
     $whoops->allowQuit(false);
     $whoops->pushHandler($container->get('Zend\\Expressive\\WhoopsPageHandler'));
     $this->registerJsonHandler($whoops, $config);
     $whoops->register();
     return $whoops;
 }
コード例 #12
0
 /**
  * @param Application $app
  */
 public function register(Application $app)
 {
     // There's only ever going to be one error page...right?
     $app['whoops.error_page_handler'] = $app->share(function () {
         if (PHP_SAPI === 'cli') {
             return new PlainTextHandler();
         } else {
             return new PrettyPageHandler();
         }
     });
     // Retrieves info on the Silex environment and ships it off
     // to the PrettyPageHandler's data tables:
     // This works by adding a new handler to the stack that runs
     // before the error page, retrieving the shared page handler
     // instance, and working with it to add new data tables
     $app['whoops.silex_info_handler'] = $app->protect(function () use($app) {
         try {
             /** @var Request $request */
             $request = $app['request'];
         } catch (RuntimeException $e) {
             // This error occurred too early in the application's life
             // and the request instance is not yet available.
             return;
         }
         /** @var Handler $errorPageHandler */
         $errorPageHandler = $app["whoops.error_page_handler"];
         if ($errorPageHandler instanceof PrettyPageHandler) {
             /** @var PrettyPageHandler $errorPageHandler */
             // General application info:
             $errorPageHandler->addDataTable('Silex Application', array('Charset' => $app['charset'], 'Locale' => $app['locale'], 'Route Class' => $app['route_class'], 'Dispatcher Class' => $app['dispatcher_class'], 'Application Class' => get_class($app)));
             // Request info:
             $errorPageHandler->addDataTable('Silex Application (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()));
         }
     });
     $app['whoops'] = $app->share(function () use($app) {
         $run = new Run();
         $run->allowQuit(false);
         $run->pushHandler($app['whoops.error_page_handler']);
         $run->pushHandler($app['whoops.silex_info_handler']);
         return $run;
     });
     $app->error(function ($e) use($app) {
         $method = Run::EXCEPTION_HANDLER;
         ob_start();
         $app['whoops']->{$method}($e);
         $response = ob_get_clean();
         $code = $e instanceof HttpException ? $e->getStatusCode() : 500;
         return new Response($response, $code);
     });
     $app['whoops']->register();
 }
コード例 #13
0
 /**
  * Render an exception into an HTTP response.
  *
  * When debugging is enabled, we make the error pretty using Whoops
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception                $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($this->isHttpException($e)) {
         return $this->renderHttpException($e);
     }
     if (config('app.debug')) {
         $whoops = new Run();
         $whoops->pushHandler($request->ajax() ? new JsonResponseHandler() : new PrettyPageHandler());
         $whoops->allowQuit(false);
         $whoops->writeToOutput(false);
         return response($whoops->handleException($e), $whoops->sendHttpCode());
     }
     return parent::render($request, $e);
 }
コード例 #14
0
ファイル: WhoopsHandler.php プロジェクト: gobline/application
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, \Exception $e)
 {
     if ($this->logger) {
         $this->logger->log($this->logLevel, $e->getMessage(), ['exception' => $e]);
     }
     $whoops = new Run();
     $whoops->allowQuit(false);
     $whoops->pushHandler(new PrettyPageHandler());
     $whoops->register();
     $method = Run::EXCEPTION_HANDLER;
     ob_start();
     $whoops->{$method}($e);
     $content = ob_get_clean();
     return new HtmlResponse($content, 500);
 }
コード例 #15
0
ファイル: Whoops.php プロジェクト: dhazelett/stack-whoops
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $this->app['exception_handler']->disable();
     $handler = new Run();
     $handler->allowQuit(false);
     if ($this->options['handler'] instanceof \Closure) {
         $handler->pushHandler($this->options['handler']);
     } elseif (is_string($this->options['handler'])) {
         $handler->pushHandler(new $this->options['handler']());
     } else {
         throw new \InvalidArgumentException(sprintf('%s requires a valid handler', __CLASS__));
     }
     $handler->register();
     $this->app['whoops_handler'] = $handler;
     return $this->app->handle($request, $type, $catch);
 }
コード例 #16
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;
 }
コード例 #17
0
ファイル: WhoopsServiceProvider.php プロジェクト: d-m-/bolt
 /**
  * {@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);
     });
 }
コード例 #18
0
 /**
  * @return Run
  */
 protected function getRunInstance()
 {
     $run = new Run();
     $run->allowQuit(false);
     return $run;
 }
コード例 #19
0
 /**
  * Initializes the error handler.
  * @return ErrorHandler The initializes error handler
  */
 private function initializeErrorHandler() : ErrorHandler
 {
     $errorHandler = new ErrorHandler();
     $errorHandler->allowQuit(false);
     $errorHandler->writeToOutput(false);
     if ($this->errorLog !== null) {
         $logger = new PlainTextHandler($this->getErrorLogger());
         $logger->loggerOnly(true);
         $errorHandler->pushHandler($logger);
     }
     if ($this->debug) {
         if ($this->jsonRequest) {
             $responseHandler = new JsonResponseHandler();
             $responseHandler->addTraceToOutput(true);
         } else {
             $responseHandler = new PrettyPageHandler();
         }
         $errorHandler->pushHandler($responseHandler);
     }
     return $errorHandler;
 }
コード例 #20
0
 protected function getWhoops(ServerRequestInterface $request)
 {
     $whoops = new Run();
     switch ($this->getAcceptType($request)) {
         case 'html':
             $whoops->pushHandler(new PrettyPageHandler());
             break;
         case 'json':
             $whoops->pushHandler(new JsonResponseHandler());
             break;
         default:
             $whoops->pushHandler(new PlainTextHandler());
     }
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     $whoops->sendHttpCode(false);
     return $whoops;
 }
コード例 #21
0
 /**
  * @param Whoops $whoops
  *
  * @return void
  */
 public function prepareWhoops(Whoops $whoops)
 {
     set_error_handler([$whoops, Whoops::ERROR_HANDLER]);
     $whoops->writeToOutput(false);
     $whoops->allowQuit(false);
 }
コード例 #22
0
<?php

declare (strict_types=1);
use function DI\get;
use Interop\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Stratify\ErrorHandlerModule\ErrorHandlerMiddleware;
use Stratify\ErrorHandlerModule\ErrorResponder\ErrorResponder;
use Stratify\ErrorHandlerModule\ErrorResponder\SimpleProductionResponder;
use Stratify\ErrorHandlerModule\ErrorResponder\WhoopsResponder;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
return [ErrorHandlerMiddleware::class => function (ContainerInterface $c) {
    $logger = $c->has(LoggerInterface::class) ? $c->get(LoggerInterface::class) : new NullLogger();
    return new ErrorHandlerMiddleware($c->get(ErrorResponder::class), $logger);
}, ErrorResponder::class => get(SimpleProductionResponder::class), WhoopsResponder::class => DI\object()->constructor(get('error_handler.whoops')), 'error_handler.whoops' => function () {
    $whoops = new Run();
    $whoops->writeToOutput(false);
    $whoops->allowQuit(false);
    $handler = new PrettyPageHandler();
    $handler->handleUnconditionally(true);
    $whoops->pushHandler($handler);
    return $whoops;
}];
コード例 #23
0
ファイル: Aplicacion.php プロジェクト: armazon/armazon
 /**
  * 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;
 }