本文整理汇总了PHP中Whoops\Run::pushHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP Run::pushHandler方法的具体用法?PHP Run::pushHandler怎么用?PHP Run::pushHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Whoops\Run
的用法示例。
在下文中一共展示了Run::pushHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* @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();
}
示例2: registerWhoops
/**
* registerWhoops
*
* @return void
*/
public static function registerWhoops()
{
self::$whoops = new Run();
self::$handler = new PrettyPageHandler();
self::$whoops->pushHandler(self::$handler);
self::$whoops->register();
}
示例3: __invoke
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);
}
示例4: __invoke
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);
}
示例5: register
public function register()
{
$error_page = new PrettyPageHandler();
$error_page->setEditor('sublime');
$this->whoops->pushHandler($error_page);
$this->whoops->register();
}
示例6: __invoke
/**
* @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;
}
}
示例7: __construct
/**
* @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();
}
示例8: __construct
/**
* @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();
}
示例9: handleException
/**
* 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;
}
示例10: onRequest
/**
* 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());
}
示例11: __construct
/**
* @param Run $whoops
*/
public function __construct(Run $whoops)
{
$this->whoops = $whoops;
$this->whoops->allowQuit(false);
$this->whoops->writeToOutput(false);
$this->whoops->pushHandler(new PrettyPageHandler());
}
示例12: registerWhoops
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;
});
}
示例13: getWhoopsInstance
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;
}
示例14: provideServices
/**
* 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]);
}
示例15: __construct
/**
* 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();
}
}