本文整理汇总了PHP中Whoops\Run类的典型用法代码示例。如果您正苦于以下问题:PHP Run类的具体用法?PHP Run怎么用?PHP Run使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Run类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
});
}
示例2: 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();
}
示例3: registerWhoops
/**
* registerWhoops
*
* @return void
*/
public static function registerWhoops()
{
self::$whoops = new Run();
self::$handler = new PrettyPageHandler();
self::$whoops->pushHandler(self::$handler);
self::$whoops->register();
}
示例4: registerErrorHandler
/**
* Register the error handler for the application.
*/
private function registerErrorHandler()
{
$run = new Whoops\Run();
$handler = new PlainTextHandler();
$run->pushHandler($handler);
$run->register();
}
示例5: _readConfigs
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');
}
}
}
示例6: debugRender
/**
* @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);
}
示例7: __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);
}
示例8: appException
/**
* 自定义异常处理
*
* @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;
}
示例9: initWhoopsErrorHandler
/**
* 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;
}
示例10: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
$whoops = new Run();
$whoops->pushHandler(new PrettyPageHandler());
$whoops->register();
}
示例11: registerErrorHandler
protected function registerErrorHandler()
{
$run = new WhoopsRun();
$handler = new PrettyPageHandler();
$run->pushHandler($handler);
$run->register();
}
示例12: __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);
}
示例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: __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();
}
示例15: __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();
}