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; }); }
/** * @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(); }
/** * registerWhoops * * @return void */ public static function registerWhoops() { self::$whoops = new Run(); self::$handler = new PrettyPageHandler(); self::$whoops->pushHandler(self::$handler); self::$whoops->register(); }
/** * Register the error handler for the application. */ private function registerErrorHandler() { $run = new Whoops\Run(); $handler = new PlainTextHandler(); $run->pushHandler($handler); $run->register(); }
private function _readConfigs() { $domain = 'cli'; if (!$this->isRunningInConsole()) { $domain = str_replace('www.', '', $_SERVER['SERVER_NAME']); } $files = scandir(APP_ROOT . DS . 'Config' . DS); foreach ($files as $file) { if (preg_match("#{$domain}\\.php\$#", $file)) { $this['config']['app'] = (require APP_ROOT . '/Config/' . $file); continue; } if (preg_match('#(.+?)\\.php$#', $file, $matches)) { $this['config'][$matches[1]] = (require_once APP_ROOT . DS . 'Config' . DS . $file); } } $this['config']['database'] = $this['config']['database'][$this['config']['app']['environment']]; if ($this['config']['app.debug'] === true) { error_reporting(E_ALL); ini_set("display_errors", 1); if (!$this->isRunningInConsole()) { $whoops = new Run(); $whoops->pushHandler(new PrettyPageHandler()); $whoops->register(); } } else { error_reporting(0); ini_set("display_errors", 0); if (!$this->isRunningInConsole()) { ExceptionHandler::setApp($this); set_exception_handler('Primer\\Error\\ExceptionHandler::handleException'); } } }
/** * @param \Exception $e * @return \Illuminate\Http\Response */ protected function debugRender(Exception $e) { $whoops = new WhoopsRun(); $whoops->pushHandler(new WhoopsPrettyPageHandler()); $response = $this->convertExceptionToResponse($e); return new HttpResponse($whoops->handleException($e), $response->getStatusCode(), $response->headers); }
/** * @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; } }
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); }
/** * 自定义异常处理 * * @param mixed $e 异常对象 */ public function appException(&$e) { if (Cml::$debug) { $run = new Run(); $run->pushHandler(Request::isCli() ? new PlainTextHandler() : new PrettyPageHandler()); $run->handleException($e); } else { $error = []; $error['message'] = $e->getMessage(); $trace = $e->getTrace(); $error['files'][0] = $trace[0]; if (substr($e->getFile(), -20) !== '\\Tools\\functions.php' || $e->getLine() !== 90) { array_unshift($error['files'], ['file' => $e->getFile(), 'line' => $e->getLine(), 'type' => 'throw']); } //正式环境 只显示‘系统错误’并将错误信息记录到日志 Log::emergency($error['message'], [$error['files'][0]]); $error = []; $error['message'] = Lang::get('_CML_ERROR_'); if (Request::isCli()) { \Cml\pd($error); } else { header('HTTP/1.1 500 Internal Server Error'); View::getEngine('html')->reset()->assign('error', $error); Cml::showSystemTemplate(Config::get('html_exception')); } } exit; }
public function register(ContainerInterface $app) { $whoops = new Whoops(); $whoops->pushHandler(new PrettyPageHandler()); $whoops->register(); $app->instance(Whoops::class, $whoops); }
/** * Send any Exceptions or PHP errors to the Whoops! Error Handler * * @return $this */ public function initWhoopsErrorHandler() { $whoops = new WhoopsRun(); $handler = new WhoopsPrettyPageHandler(); $whoops->pushHandler($handler)->register(); return $this; }
/** * 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; }
/** * Bootstrap the application services. * * @return void */ public function boot() { // $whoops = new Run(); $whoops->pushHandler(new PrettyPageHandler()); $whoops->register(); }
public function register() { $error_page = new PrettyPageHandler(); $error_page->setEditor('sublime'); $this->whoops->pushHandler($error_page); $this->whoops->register(); }
/** * Display the given exception to the user. * * @param \Exception $exception */ public function display(Exception $exception) { if (!$this->runningInConsole and !headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } $this->whoops->handleException($exception); }
protected function registerErrorHandler() { $run = new WhoopsRun(); $handler = new PrettyPageHandler(); $run->pushHandler($handler); $run->register(); }
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); }
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; }
/** * @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(); }
/** * @param Exception $e * * @return string */ private function debugException(Exception $e) { $whoops = new Run(); $whoops->pushHandler(new PrettyPageHandler()); $content = $whoops->handleException($e); return $content; }
private function registerWhoops() { // Register whoops $whoops = new Whoops(); $ph = new PrettyPageHandler(); $whoops->pushHandler($ph); $whoops->register(); }
/** * Returns the whoops instance. * * @return Whoops */ private function getWhoops() { $whoops = new Whoops(); $whoops->allowQuit(false); $whoops->writeToOutput(false); $whoops->pushHandler(new PrettyPageHandler()); return $whoops; }
protected function handleWithWhoops(Exception $exception) { $whoops = new Run(); $whoops->allowQuit(false); $whoops->writeToOutput(false); $whoops->pushHandler(new PrettyPageHandler()); return $whoops->handleException($exception); }
/** * Create a Whoops response for the given exception * * @param Exception $e * @return \Illuminate\Http\Response */ protected function convertExceptionToWhoops(Exception $e) { $whoops = new Whoops(); $whoops->pushHandler($this->getWhoopsHandler()); $statusCode = method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500; $headers = method_exists($e, 'getHeaders') ? $e->getHeaders() : []; return response()->make($whoops->handleException($e), $statusCode, $headers); }
/** * 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; }
public function setErrorTraits($traits) { $run = new Run(); $handler = new PrettyPageHandler(); $handler->addDataTable('Traits', $traits); $run->pushHandler($handler); $run->register(); }
/** * 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); }
/** * @param Pimple\Container $app * @return void */ public function register(Container $app) { $app['whoops'] = function (Container $app) { $whoops = new Run(); $whoops->pushHandler(new PrettyPageHandler()); return $whoops; }; }
/** * Register method. */ public function register() { $this->container->add(Run::class, function () { $whoops = new Run(); $whoops->pushHandler(new PrettyPageHandler()); return $whoops; }); }