예제 #1
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;
 }
예제 #2
0
파일: System.php 프로젝트: brunomrpx/willer
 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));
 }
예제 #3
0
 /**
  * Handle an error with Whoops
  *
  * @return string
  */
 public function handle()
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler());
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     return $whoops->handleException($this->exception);
 }
예제 #4
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());
 }
예제 #5
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());
 }
예제 #6
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());
 }
예제 #7
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();
     }
 }
예제 #8
0
파일: Handler.php 프로젝트: flashtag/cms
 /**
  * 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());
 }
예제 #9
0
파일: Base.php 프로젝트: werx/skeleton
 public function initializeErrorHandler()
 {
     $whoops = new \Whoops\Run();
     if ($this->config->get('debug', false) === true) {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     } else {
         $template = $this->template;
         $whoops->pushHandler(function ($exception, $inspector, $run) use($template) {
             $template->output('common/error');
         });
     }
     $whoops->register();
 }
예제 #10
0
 private function boot()
 {
     if (ENVIRONMENT == 'development') {
         $run = new \Whoops\Run();
         $handler = new PrettyPageHandler();
         $handler->setPageTitle("We're all going to be fired!");
         $handler->setEditor('textmate');
         $run->pushHandler($handler);
         $handler = new JsonResponseHandler();
         $handler->onlyForAjaxRequests(true);
         $run->pushHandler($handler);
         $run->register();
     }
 }
예제 #11
0
 public static function run()
 {
     //初始化session
     session_start();
     //初始化配置文件
     Config::getInstance();
     $appConfig = Config::get('app');
     //初始化主题
     $public = $appConfig['public'] ? $appConfig['public'] : 'public';
     Filesystem::mkdir($public, 444);
     if (!empty($appConfig['theme'])) {
         defined("APP_THEME") or define("APP_THEME", $public . '/' . $appConfig['theme']);
     } else {
         defined("APP_THEME") or define("APP_THEME", $public);
     }
     //初始化应用名字
     if (!empty($appConfig['name'])) {
         defined("APP_NAME") or define("APP_NAME", $appConfig['name']);
     } else {
         defined("APP_NAME") or define("APP_NAME", 'Simpla');
     }
     //初始化应用URL域名
     defined("BASE_URL") or define("BASE_URL", $appConfig['url']);
     //是否开启错误提示
     if ($appConfig['debug'] == 1) {
         error_reporting(E_ALL);
     } else {
         error_reporting(0);
     }
     //初始化数据库
     Model::getInstance();
     //初始化缓存
     ICache::getInstance();
     Cache::getInstance();
     //初始化whoops
     $run = new \Whoops\Run();
     $handler = new PrettyPageHandler();
     // 设置错误页面的标题
     $handler->setPageTitle("Whoops! 出现了一个错误.");
     $run->pushHandler($handler);
     //设置ajax错误提示.
     if (\Whoops\Util\Misc::isAjaxRequest()) {
         $run->pushHandler(new JsonResponseHandler());
     }
     // 注册handler
     $run->register();
     //路由处理
     Route::check();
 }
예제 #12
0
 public function register()
 {
     if (C('phpunit')) {
         return;
     }
     $whoops = new \Whoops\Run();
     $pretty = new \Whoops\Handler\PrettyPageHandler();
     $whoops->pushHandler($pretty);
     $jsonHandler = new \Whoops\Handler\JsonResponseHandler();
     $jsonHandler->onlyForAjaxRequests(true);
     $whoops->pushHandler($jsonHandler);
     $whoops->register();
     restore_error_handler();
     spl_autoload_register(array($this, 'autoload'));
 }
 public function register($app)
 {
     /**
      * Error handler
      */
     $whoops = new \Whoops\Run();
     if (getenv('MODE') === 'dev') {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     } else {
         $whoops->pushHandler(function () {
             Response::create('Something broke', Response::HTTP_INTERNAL_SERVER_ERROR)->send();
         });
     }
     $whoops->register();
 }
예제 #14
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()
 }
예제 #15
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);
 }
예제 #16
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 ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if (config('app.debug')) {
         $whoops = new \Whoops\Run();
         if ($request->ajax()) {
             $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
         } else {
             $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         }
         return response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
     }
     return parent::render($request, $e);
 }
예제 #17
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());
 }
예제 #18
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());
 }
예제 #19
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();
 }
예제 #20
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');
 }
예제 #21
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());
 }
 /**
  * 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());
 }
예제 #23
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);
 }
예제 #24
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);
 }
예제 #25
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)
 {
     if ($e instanceof ForbiddenException) {
         return response()->view('errors.forbidden');
     }
     if ($e instanceof NotFoundHttpException) {
         return response()->view('errors.404');
     }
     if (env('APP_DEBUG', false)) {
         $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());
     }
 }
예제 #26
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());
 }
예제 #27
0
파일: phpw.php 프로젝트: ngangchill/po
 static function reload()
 {
     $run = new Whoops\Run();
     $handler = new PrettyPageHandler();
     $CI =& get_instance();
     $handler->setEditor("sublime");
     // Set the editor used for the "Open" link
     $handler->addDataTable("Extra Info", array("Name" => 'Forhad Ahmed', "email" => "*****@*****.**"));
     // Set the title of the error page:
     $handler->setPageTitle("Whoops! There was a problem.");
     $run->pushHandler($handler);
     $CI =& load_class('Input');
     if ($CI->is_ajax_request() == true) {
         $run->pushHandler(new JsonResponseHandler());
     }
     // Register the handler with PHP, and you're set!
     $run->register();
 }
예제 #28
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));
 }
예제 #29
0
파일: Error.php 프로젝트: mermetbt/biome
 public static function init()
 {
     error_reporting(E_ALL);
     if (Config\Config::get('WHOOPS_ERROR', FALSE) || Config\Config::get('DEBUG', FALSE)) {
         $whoops = new \Whoops\Run();
         $request = \Biome\Biome::getService('request');
         if ($request->acceptHtml()) {
             $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         } else {
             if (\Whoops\Util\Misc::isCommandLine()) {
                 $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler());
             } else {
                 $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
             }
         }
         $whoops->register();
     }
 }
예제 #30
0
 public function init()
 {
     if (APP_DEBUG) {
         // 注册错误页面
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     }
 }