本文整理汇总了PHP中Whoops\Run::sendHttpCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Run::sendHttpCode方法的具体用法?PHP Run::sendHttpCode怎么用?PHP Run::sendHttpCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Whoops\Run
的用法示例。
在下文中一共展示了Run::sendHttpCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
示例2: render
/**
* 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);
}
示例3: register
public function register()
{
$this->run->register();
$this->setupDefaultHandler();
if ($this->displayExceptionsinHtml) {
$this->setupPrettyPageHandler();
}
if ($this->jsonHandlerConfig['display']) {
$this->run->sendHttpCode(null);
$this->setupJsonResponseHandler();
}
if ($this->getLogger()) {
$this->setupLoggerHandler();
}
}
示例4: getWhoops
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;
}