Exemplo n.º 1
0
 /**
  * Render an exception into a response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function render($request, Exception $e)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     return new Response($whoops->handleException($e));
     //, $e->getStatusCode(), $e->getHeaders()
 }
Exemplo n.º 2
0
 public function handle()
 {
     $action = $this->url->get("action", "default");
     $whoops = new \Whoops\Run();
     if ($this->url->get("ajax", false)) {
         $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     } else {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     }
     $whoops->register();
     $result = null;
     if (method_exists($this, "handle_" . $action)) {
         $result = call_user_func(array($this, "handle_" . $action));
     } else {
         throw new Exception("Unknown action");
     }
     $output = "";
     if (is_string($result)) {
         $newResult = array('type' => 'transclude', 'content' => $result);
         $result = $newResult;
     }
     switch ($result['type']) {
         case "template":
             $output = $this->twig->renderTemplateToString($result['template'], $result['data']);
             break;
         case "json":
             $this->app->setJsonResponse(true);
             $data = $result['data'];
             $data['flashbag'] = FlashBag::getFlashes();
             $output = json_encode($data);
             break;
         case "redirect":
             $this->app->_requestRedirect($result['url']);
             return;
             break;
         case "transclude":
             $pageMap = [];
             /** @var BasePage $pageItem */
             foreach ($this->app->getPages() as $pageItem) {
                 $pageMap[] = array('id' => $pageItem->getId(), 'name' => $pageItem->getName());
             }
             ValueBag::set("flashbag", FlashBag::getFlashes());
             $data = array('valueBag' => json_encode(ValueBag::getValues()), 'staticRoot' => $this->app->getStaticRoot(), 'pageMap' => $pageMap, 'defaultUrl' => $this->routeGen->defaultRoute(), 'title' => $this->app->getAppName(), 'userParams' => $this->app->getUserParams(), 'pageTitle' => '');
             if ($this->page !== null) {
                 $data['page'] = $this->page;
                 $data['currentId'] = $this->page->getId();
                 $data['pageTitle'] = $this->page->getName();
             } else {
                 $data['currentId'] = -1;
             }
             $data['page_content'] = $result['content'];
             $data['dev'] = false;
             // change to true to load unminified js
             $output = $this->twig->renderTemplateToString("main_page.twig", $data);
             break;
         default:
             throw new Exception("Unknown result type");
     }
     return $output;
 }
Exemplo n.º 3
0
 /**
  * HTTPレスポンスに対応する例外をレンダー
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception               $e
  *
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if (config('app.debug')) {
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Hander\PrettyPageHander());
         return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
     }
     // CSRFトークンが存在しない、トークン不一致時に投げられる。
     // TokenMismatchException例外を403で処理。
     // もちろん適切であれば、HTTPステータスは自由に設定できる。
     if ($e instanceof TokenMismatchException) {
         // abortヘルパーによりSymfony\Component\HttpFoundation\Exception\HttpException例外が
         // 投げられ、再度このrenderメソッドで処理される。この例外の
         // ステータスコードに一致するビューがapp/resources/views/errorsに
         // 存在していれば、そのビューが表示される。今回は403.blade.phpファイルが
         // 存在しているため、このファイルの内容がエラーページとして表示される。
         abort(403);
     }
     // このrenderメソッドに最初から含まれている処理。
     // EloquentのfindOrFailソッドなどが投げるModelNotFoundException例外を
     // 404エラーにしている。
     if ($e instanceof ModelNotFoundException) {
         // 404エラー例外はabort(404)を使わず、次のように発生可能。
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     return parent::render($request, $e);
 }
Exemplo n.º 4
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $handler = $_SERVER['REQUEST_METHOD'] == "GET" ? new \Whoops\Handler\PrettyPageHandler() : new \Whoops\Handler\PlainTextHandler();
     $whoops->pushHandler($handler);
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 5
0
 public function renderExceptionWithWhoops($request, $e)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     return new Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
     //return Response::view('errors.503');
 }
Exemplo n.º 6
0
 protected function renderExceptionWithWhoops(Exception $e) : Response
 {
     $this->unsetSensitiveData();
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 7
0
 private function readyErrorHandler()
 {
     if (empty(DEBUG)) {
         return false;
     }
     $whoops_run = new \Whoops\Run();
     $whoops_pretty_page_handler = new \Whoops\Handler\PrettyPageHandler();
     $whoops_json_response_handler = new \Whoops\Handler\JsonResponseHandler();
     $whoops_json_response_handler->onlyForAjaxRequests(true);
     $whoops_run->pushHandler($whoops_pretty_page_handler);
     $whoops_run->pushHandler(function ($exception, $inspector, $whoops_run) {
         $inspector->getFrames()->map(function ($frame) {
             $frame_function = $frame->getFunction();
             $frame_class = $frame->getClass();
             $frame_args = $frame->getArgs();
             if (!empty($frame_function)) {
                 $frame->addComment($frame_function, 'Function');
             }
             if (!empty($frame_class)) {
                 $frame->addComment($frame_class, 'Class');
             }
             if (!empty($frame_args)) {
                 $frame->addComment(print_r($frame_args, true), 'Args');
             }
             return $frame;
         });
     });
     $whoops_run->pushHandler($whoops_json_response_handler);
     $whoops_run->register();
     $whoops_pretty_page_handler->addDataTable('Willer Contants', array('URL_PREFIX' => URL_PREFIX, 'REQUEST_URI' => REQUEST_URI, 'ROOT_PATH' => ROOT_PATH, 'DATABASE_PATH' => DATABASE_PATH, 'DATABASE' => DATABASE));
 }
Exemplo n.º 8
0
 public static function enableDebug()
 {
     // 设置 PHP 调试环境
     ini_set('display_errors', 1);
     error_reporting(E_ALL | E_STRICT);
     // 开启 debug log
     BzfDebug::startDebugLogCollector();
     // 当前目录 autoload
     \Core\Plugin\SystemHelper::addAutoloadPath(realpath(dirname(__FILE__)));
     $handler = new \Whoops\Handler\PrettyPageHandler();
     // 增加额外的日志输出
     $handler->addDataTableCallback('LOGS', function () {
         // 取得 logCollector
         $logCollector = BzfDebug::startDebugLogCollector();
         $logArray = $logCollector->getLogArray();
         // 由于 debug 只支持 key-->value 显示,我们只能简单一点了
         $displayArray = array();
         $index = 0;
         foreach ($logArray as $logItem) {
             $displayArray['' . sprintf('%02d', $index) . '|' . str_pad($logItem['level'], 10, ' ', STR_PAD_LEFT) . '|' . $logItem['source']] = $logItem['msg'];
             $index++;
         }
         return $displayArray;
     });
     $run = new \Whoops\Run();
     $run->pushHandler($handler);
     $run->register();
 }
 /**
  * Render an ajax exception using Whoops.
  *
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderAjaxExceptionWithWhoops($e)
 {
     $whoops = new \Whoops\Run();
     $jsonHandler = new \Whoops\Handler\JsonResponseHandler();
     $jsonHandler->addTraceToOutput(true);
     $whoops->pushHandler($jsonHandler);
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 10
0
 /**
  * Render an exception into an HTTP response using Whoops.
  *
  * @return \Illuminate\Http\Response
  */
 protected function whoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $handler->setEditor('sublime');
     $whoops->pushHandler($handler);
     return response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 11
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $handler->addResourcePath(public_path());
     $handler->addCustomCss('css/whoops.min.css');
     $whoops->pushHandler($handler);
     return new \Illuminate\Http\Response($whoops->handleException($e));
 }
Exemplo n.º 12
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception                $exception
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops($request, Exception $exception)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     if ($request->ajax()) {
         $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     }
     return new Response($whoops->handleException($exception), $exception->getStatusCode(), $exception->getHeaders());
 }
Exemplo n.º 13
0
 /**
  * Render an exception using Whoops.
  * 
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     var_dump($e);
     exit;
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 14
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception                $exception
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $exception)
 {
     $json = new \Whoops\Handler\JsonResponseHandler();
     $json->onlyForAjaxRequests(true);
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->pushHandler($json);
     return new \Illuminate\Http\Response($whoops->handleException($exception), $exception->getStatusCode(), $exception->getHeaders());
 }
Exemplo n.º 15
0
 protected function convertExceptionToResponse(Exception $e)
 {
     if (config('app.debug')) {
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         return response()->make($whoops->handleException($e), method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500, method_exists($e, 'getHeaders') ? $e->getHeaders() : []);
     }
     return parent::convertExceptionToResponse($e);
 }
Exemplo n.º 16
0
 public function init()
 {
     if (APP_DEBUG) {
         // 注册错误页面
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     }
 }
Exemplo n.º 17
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if (config('app.debug')) {
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         return response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
     }
     return parent::render($request, $e);
 }
Exemplo n.º 18
0
 public function __construct()
 {
     spl_autoload_register(array($this, 'loadClass'));
     GlizyErrorHandler::unregister();
     $whoops = new \Whoops\Run();
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $whoops->pushHandler($handler);
     $whoops->register();
 }
Exemplo n.º 19
0
 /**
  * Render an exception into a response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function render($request, Exception $e)
 {
     $whoops = new \Whoops\Run();
     if ($request->ajax()) {
         $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     } else {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     }
     return new Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 20
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $handler = new \Whoops\Handler\PrettyPageHandler();
     if ($e instanceof ValidationException) {
         $handler->addDataTable('Validation Errors', $e->validator->errors()->all());
     }
     $whoops->pushHandler($handler);
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 21
0
 public function register(Application $app)
 {
     $whoops = new \Whoops\Run();
     $whoops->allowQuit(false);
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $handler->setPageTitle("Whoops! There was a problem.");
     $whoops->pushHandler($handler);
     $whoops->register();
     $app->set('Whoops', $whoops);
 }
Exemplo n.º 22
0
 private static function openWhoops()
 {
     if (self::$config['DEBUG'] === true) {
         error_reporting(E_ALL);
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     } else {
         error_reporting(0);
     }
 }
 /**
  * Register the Whoops error display service.
  *
  * @return void
  */
 protected function registerWhoops()
 {
     $this->registerWhoopsHandler();
     $this->app['whoops'] = $this->app->share(function ($app) {
         // We will instruct Whoops to not exit after it displays the exception as it
         // will otherwise run out before we can do anything else. We just want to
         // let the framework go ahead and finish a request on this end instead.
         with($whoops = new \Whoops\Run())->allowQuit(false);
         return $whoops->pushHandler($app['whoops.handler']);
     });
 }
Exemplo n.º 24
0
 /**
  * Report or log an exception.
  *
  * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  *
  * @param  \Exception  $e
  * @return void
  */
 public function report(Exception $e)
 {
     if ($e instanceof \PHPUnit_Framework_Exception) {
         echo $e->getMessage();
         echo $e->getTraceAsString();
     }
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     return parent::report($e);
 }
 public function __construct()
 {
     // Setup whoops exception handler
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     // Initialize services
     $this->setUpServices();
     // Create the lazy service container
     $this->container = new DependencyInjector($this->services);
 }
Exemplo n.º 26
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return Response
  */
 protected function renderExceptionWithWhoops($request, Exception $e)
 {
     $whoops = new \Whoops\Run();
     if ($request->ajax()) {
         $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     } elseif (app()->environment() == 'testing') {
         $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler());
     } else {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     }
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Exemplo n.º 27
0
 /**
  * Init Whoops based on App conditional rule.
  */
 public function init()
 {
     if (TIGA_DEBUG == true && !$this->app->isConsole()) {
         $whoops = new \Whoops\Run();
         if ($this->app['request']->isJson()) {
             $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
         } else {
             $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         }
         $whoops->register();
     }
 }
Exemplo n.º 28
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if (config('app.debug')) {
         $whoopsHandler = new \Whoops\Handler\PrettyPageHandler();
         $whoopsHandler->setEditor('sublime');
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($whoopsHandler);
         return $whoops->handleException($e);
     } else {
         return parent::render($request, $e);
     }
 }
 /**
  * This method will handle any Exception thrown.
  *
  * @param Exception $exception The exception to be handled
  *
  * @return void
  */
 public static function handle($exception)
 {
     // Verify if the debug level is at least the minDebugLevel
     if (Configure::read('debug') >= self::$minDebugLevel) {
         // Debug level is high enough, use the Whoops handler
         $Whoops = new Whoops\Run();
         $Whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
         $Whoops->handleException($exception);
     } else {
         // Debug level is too low, fall back to CakePHP default ErrorHandler
         ErrorHandler::handleException($exception);
     }
 }
Exemplo n.º 30
0
 /**
  * Render an exception using Whoops.
  *
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     /* if (method_exists('getStatisCode', $e)) {
            return new \Illuminate\Http\Response(
                $whoops->handleException($e),
                $e->getStatusCode(),
                $e->getHeaders()
            );
        }*/
     return $whoops->handleException($e);
 }