本文整理汇总了PHP中Pimple\Container::error方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::error方法的具体用法?PHP Container::error怎么用?PHP Container::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple\Container
的用法示例。
在下文中一共展示了Container::error方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* @param Container|Application $app
*/
public function register(Container $app)
{
ini_set('log_errors', 1);
strtoupper(env('APP_ENV')) === 'PRODUCTION' ? ini_set('display_errors', 0) : ini_set('display_errors', 1);
$app['debug'] = env('DEBUG');
!$app['debug'] ?: ($app['dump'] = $app->protect(function ($var) {
return (new VarDumper())::dump($var);
}));
/** Register the app error factory */
$app->error(function (\Exception $e) use($app) {
// handle HTTP exceptions
if (get_class($e) === NotFoundHttpException::class) {
/** @var NotFoundHttpException $e */
/** @noinspection DegradedSwitchInspection */
switch ($e->getStatusCode()) {
case 404:
return response(view('404.html', ['error' => '404 - Page Not Found.']), 404);
break;
default:
$message = 'We are sorry, but something went terribly wrong.';
}
return new Response($message);
}
// not an HTTP exception
throw $e;
});
if ($app['debug']) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
# core debug utilities
# note that debug requires that the environment has been loaded
include_once BOOT . 'assets/debug.php';
}
}
示例2: register
public function register(Container $app)
{
if ($app instanceof Application) {
$app->error(function (\Exception $e, Request $request, $code) use($app) {
return $app->offsetGet("error.controller")->index($e, $request, $code);
});
}
}
示例3: register
public function register(Container $app)
{
$app['bugsnag'] = function ($app) {
$client = Client::make($app['bugsnag.options']['apiKey']);
$client->setNotifier(['name' => 'Silex Bugsnag', 'version' => static::VERSION, 'url' => 'https://github.com/fortis/silex-bugsnag']);
Handler::register($client);
return $client;
};
$app->error(function (\Exception $error, Request $request) use($app) {
$params['request'] = ['params' => $request->query->all(), 'requestFormat' => $request->getRequestFormat()];
$app['bugsnag']->notifyException($error);
});
}