/**
  * @see Silex\ServiceProviderInterface::register
  * @param  Silex\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 () {
         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 {
             $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;
         }
         // General application info:
         $app['whoops.error_page_handler']->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:
         $app['whoops.error_page_handler']->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->pushHandler($app['whoops.error_page_handler']);
         $run->pushHandler($app['whoops.silex_info_handler']);
         return $run;
     });
     $app->error(array($app['whoops'], Run::EXCEPTION_HANDLER));
     $app['whoops']->register();
 }
Exemple #2
0
 /**
  * registerWhoops
  *
  * @return void
  */
 public static function registerWhoops()
 {
     self::$whoops = new Run();
     self::$handler = new PrettyPageHandler();
     self::$whoops->pushHandler(self::$handler);
     self::$whoops->register();
 }
 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);
 }
 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()
 {
     $error_page = new PrettyPageHandler();
     $error_page->setEditor('sublime');
     $this->whoops->pushHandler($error_page);
     $this->whoops->register();
 }
Exemple #6
0
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     try {
         return $next($request, $response);
     } catch (Exception $e) {
         if ($this->logger) {
             $this->logger->error($e->getMessage(), ['exception' => $e]);
         }
         $type = $this->type($request);
         $response = $response->withHeader('Content-Type', $type);
         try {
             if (method_exists($e, 'getHttpStatus')) {
                 $code = $e->getHttpStatus();
             } else {
                 $code = $e->getCode();
             }
             $response = $response->withStatus($code);
         } catch (InvalidArgumentException $_) {
             // Exception did not contain a valid code
             $response = $response->withStatus(500);
         }
         if ($e instanceof HttpException) {
             $response = $e->withResponse($response);
         }
         $handler = $this->handler($type);
         $this->whoops->pushHandler($handler);
         $body = $this->whoops->handleException($e);
         $response->getBody()->write($body);
         $this->whoops->popHandler();
         return $response;
     }
 }
 /**
  * @param Phalcon\DI $di
  */
 public function __construct(DI $di = null)
 {
     if (!$di) {
         $di = DI::getDefault();
     }
     // There's only ever going to be one error page...right?
     $di->setShared('whoops.error_page_handler', function () {
         return new PrettyPageHandler();
     });
     // Retrieves info on the Phalcon 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
     $phalcon_info_handler = function () use($di) {
         try {
             $request = $di['request'];
         } catch (Exception $e) {
             // This error occurred too early in the application's life
             // and the request instance is not yet available.
             return;
         }
         // Request info:
         $di['whoops.error_page_handler']->addDataTable('Phalcon Application (Request)', array('URI' => $request->getScheme() . '://' . $request->getServer('HTTP_HOST') . $request->getServer('REQUEST_URI'), 'Request URI' => $request->getServer('REQUEST_URI'), 'Path Info' => $request->getServer('PATH_INFO'), 'Query String' => $request->getServer('QUERY_STRING') ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getServer('SCRIPT_NAME'), 'Scheme' => $request->getScheme(), 'Port' => $request->getServer('SERVER_PORT'), 'Host' => $request->getServerName()));
     };
     $di->setShared('whoops', function () use($di, $phalcon_info_handler) {
         $run = new Run();
         $run->pushHandler($di['whoops.error_page_handler']);
         $run->pushHandler($phalcon_info_handler);
         return $run;
     });
     $di['whoops']->register();
 }
 /**
  * @param DI $di
  */
 public function __construct(DI $di = null)
 {
     if (!class_exists('\\Whoops\\Run')) {
         return;
     }
     if (!$di) {
         $di = DI::getDefault();
     }
     // There's only ever going to be one error page...right?
     $di->setShared('whoops.pretty_page_handler', function () use($di) {
         return (new DebugbarHandler())->setDi($di);
     });
     // There's only ever going to be one error page...right?
     $di->setShared('whoops.json_response_handler', function () {
         $jsonHandler = new JsonResponseHandler();
         $jsonHandler->onlyForAjaxRequests(true);
         return $jsonHandler;
     });
     $di->setShared('whoops', function () use($di) {
         $run = new Run();
         $run->silenceErrorsInPaths(array('/phalcon-debugbar/'), E_ALL);
         $run->pushHandler($di['whoops.pretty_page_handler']);
         $run->pushHandler($di['whoops.json_response_handler']);
         return $run;
     });
     $di['whoops']->register();
 }
 /**
  * Handle an exception.
  *
  * Calls on prepareWhoopsHandler() to inject additional data tables into
  * the generated payload, and then injects the response with the result
  * of whoops handling the exception.
  *
  * @param \Exception $exception
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 protected function handleException(\Exception $exception, Request $request, Response $response)
 {
     $this->prepareWhoopsHandler($request);
     $this->whoops->pushHandler($this->whoopsHandler);
     $response->getBody()->write($this->whoops->handleException($exception));
     return $response;
 }
Exemple #10
0
 /**
  * Add JSON handler to Whoops if Ajax request
  *
  * @param GetResponseEvent $event
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest() || !$event->getRequest()->isXmlHttpRequest()) {
         return;
     }
     $this->whoops->pushHandler(new JsonResponseHandler());
 }
Exemple #11
0
 /**
  * @param Run $whoops
  */
 public function __construct(Run $whoops)
 {
     $this->whoops = $whoops;
     $this->whoops->allowQuit(false);
     $this->whoops->writeToOutput(false);
     $this->whoops->pushHandler(new PrettyPageHandler());
 }
Exemple #12
0
 protected static function registerWhoops()
 {
     $app = Slim::getInstance();
     $app->container->singleton('whoopsPrettyPageHandler', function () {
         return new PrettyPageHandler();
     });
     $app->whoopsSlimInfoHandler = $app->container->protect(function () use($app) {
         try {
             $request = $app->request();
         } catch (\RuntimeException $e) {
             return;
         }
         $current_route = $app->router()->getCurrentRoute();
         $route_details = array();
         if ($current_route !== null) {
             $route_details = array('Route Name' => $current_route->getName() ?: '<none>', 'Route Pattern' => $current_route->getPattern() ?: '<none>', 'Route Middleware' => $current_route->getMiddleware() ?: '<none>');
         }
         $app->whoopsPrettyPageHandler->addDataTable('Slim Application', array_merge(array('Charset' => $request->headers('ACCEPT_CHARSET'), 'Locale' => $request->getContentCharset() ?: '<none>', 'Application Class' => get_class($app)), $route_details));
         $app->whoopsPrettyPageHandler->addDataTable('Slim Application (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()));
     });
     // Open with editor if editor is set
     $whoops_editor = $app->config('whoops.editor');
     if ($whoops_editor !== null) {
         $app->whoopsPrettyPageHandler->setEditor($whoops_editor);
     }
     $app->container->singleton('whoops', function () use($app) {
         $run = new Run();
         $run->pushHandler($app->whoopsPrettyPageHandler);
         $run->pushHandler($app->whoopsSlimInfoHandler);
         return $run;
     });
 }
 private static function getWhoopsInstance(ServerRequestInterface $request)
 {
     $whoops = new Run();
     if (php_sapi_name() === 'cli') {
         $whoops->pushHandler(new PlainTextHandler());
         return $whoops;
     }
     $format = FormatNegotiator::getPreferredFormat($request);
     switch ($format) {
         case 'json':
             $handler = new JsonResponseHandler();
             $handler->addTraceToOutput(true);
             break;
         case 'html':
             $handler = new PrettyPageHandler();
             break;
         case 'txt':
             $handler = new PlainTextHandler();
             $handler->addTraceToOutput(true);
             break;
         case 'xml':
             $handler = new XmlResponseHandler();
             $handler->addTraceToOutput(true);
             break;
         default:
             if (empty($format)) {
                 $handler = new PrettyPageHandler();
             } else {
                 $handler = new PlainTextHandler();
                 $handler->addTraceToOutput(true);
             }
     }
     $whoops->pushHandler($handler);
     return $whoops;
 }
 /**
  * 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]);
 }
 /**
  * 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();
     }
 }
Exemple #16
0
 /**
  * Render an exception using Whoops.
  *
  * @param  $request
  * @param  \Exception $e
  * @return Response
  */
 protected function renderExceptionWithWhoops($request, Exception $e)
 {
     $whoops = new Whoops\Run();
     if ($request->ajax()) {
         $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler());
     } else {
         $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
     }
     return new Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemple #17
0
 /**
  * 激活调试器
  */
 public static function enable()
 {
     if (self::$enabled) {
         return;
     }
     self::$_debugger = new Run();
     self::$_debugger->pushHandler(new PrettyPageHandler());
     self::$_debugger->register();
     self::$enabled = true;
 }
Exemple #18
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();
 }
Exemple #19
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception $e    The Exception object
  * @param  string     $json Whether to use the JsonResponseHandler instead
  *                          of the PrettyPageHandler.
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e, $json = false)
 {
     $whoops = new Whoops();
     if ($json) {
         $whoops->pushHandler(new JsonResponseHandler());
     } else {
         $whoops->pushHandler(new PrettyPageHandler());
     }
     return new Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemple #20
0
 /**
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception               $e
  *
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function renderExceptionWithWhoops($request, Exception $e)
 {
     $whoops = new Run();
     if ($request->ajax() || $request->wantsJson()) {
         $whoops->pushHandler(new JsonResponseHandler());
     } else {
         $whoops->pushHandler(new PrettyPageHandler());
     }
     return response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemple #21
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();
 }
Exemple #22
0
 /**
  * @param Request $request
  * @param Exception $exception
  * @return Response
  * @throws \InvalidArgumentException
  */
 protected function renderExceptionWithWhoops(Request $request, Exception $exception)
 {
     $whoops = new Whoops();
     if ($request->isJson() || $request->wantsJson()) {
         $whoops->pushHandler(new JsonResponseHandler());
     } else {
         $whoops->pushHandler(new PrettyPageHandler());
     }
     $code = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
     $headers = $exception instanceof HttpException ? $exception->getHeaders() : [];
     return new Response($whoops->handleException($exception), $code, $headers);
 }
 /**
  * @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();
 }
Exemple #24
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));
 }
Exemple #25
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'));
 }
Exemple #26
0
 /**
  * Set the proper Error Handler based on the Output of the page
  *
  * @param string $output
  */
 public function setHandler($output = null)
 {
     $this->_whoops->popHandler();
     if ($output == Output::JSON) {
         $this->_handler = new JsonResponseHandler();
     } else {
         if ($output == Output::XML) {
             $this->_handler = new XmlResponseHandler();
         } else {
             $this->_handler = new PlainResponseHandler();
         }
     }
     $this->_whoops->pushHandler($this->_handler);
 }
 public function register(App $glue)
 {
     $whoops = new Run();
     $logger = $glue->bound('Psr\\Log\\LoggerInterface') ? $glue->make('Psr\\Log\\LoggerInterface') : null;
     $whoops->pushHandler(new PlainTextHandler($logger));
     if ($glue->config->get('debug', false) !== true) {
         $whoops->pushHandler(new ProductionHandler($logger));
     } else {
         $whoops->pushHandler(new PrettyPageHandler($logger));
     }
     $whoops->register();
     $glue->singleton('Whoops\\Run', function () use($whoops) {
         return $whoops;
     });
 }
Exemple #28
0
 private function errors()
 {
     if ($this->environment == 'production') {
         return;
     }
     $run = new Whoops\Run();
     $handler = new Whoops\Handler\PrettyPageHandler();
     $run->pushHandler($handler);
     $run->pushHandler(function ($exception, $inspector, $run) {
         $inspector->getFrames()->map(function ($frame) {
             return $frame;
         });
     });
     $run->register();
 }
 public function register()
 {
     if (function_exists('ini_set')) {
         ini_set('display_errors', 0);
     }
     $run = new Run();
     $handler = new ErrorHandler();
     $json_handler = new JsonErrorHandler();
     $cli_handler = new PlainTextHandler();
     $cli_handler->onlyForCommandLine(true);
     $run->pushHandler($handler);
     $run->pushHandler($json_handler);
     $run->pushHandler($cli_handler);
     $run->register();
 }
Exemple #30
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'));
 }