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)); }
/** * 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()); }
/** * 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()); }
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')); }
/** * @static * @throws Exception|\Zend_Controller_Router_Exception */ public static function run() { self::setSystemRequirements(); // detect frontend (website) $frontend = Tool::isFrontend(); // enable the output-buffer, why? see in self::outputBufferStart() //if($frontend) { self::outputBufferStart(); //} self::initAutoloader(); self::initConfiguration(); self::setupFramework(); // config is loaded now init the real logger self::initLogger(); // initialize cache Cache::init(); // load plugins and modules (=core plugins) self::initModules(); self::initPlugins(); // init front controller $front = \Zend_Controller_Front::getInstance(); $conf = Config::getSystemConfig(); if (!$conf) { // redirect to installer if configuration isn't present if (!preg_match("/^\\/install.*/", $_SERVER["REQUEST_URI"])) { header("Location: /install/"); exit; } } if (self::inDebugMode() && $frontend && !$conf->general->disable_whoops && !defined("HHVM_VERSION")) { $whoops = new \Whoops\Run(); $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); $jsonErrorHandler = new \Whoops\Handler\JsonResponseHandler(); $jsonErrorHandler->onlyForAjaxRequests(true); $whoops->pushHandler($jsonErrorHandler); $whoops->register(); // add event handler before Pimcore::shutdown() to ensure fatal errors are handled by Whoops self::getEventManager()->attach("system.shutdown", array($whoops, "handleShutdown"), 10000); } $front->registerPlugin(new Controller\Plugin\ErrorHandler(), 1); $front->registerPlugin(new Controller\Plugin\Maintenance(), 2); // register general pimcore plugins for frontend if ($frontend) { $front->registerPlugin(new Controller\Plugin\Thumbnail(), 795); $front->registerPlugin(new Controller\Plugin\Less(), 799); $front->registerPlugin(new Controller\Plugin\AdminButton(), 806); } if (Tool::useFrontendOutputFilters(new \Zend_Controller_Request_Http())) { $front->registerPlugin(new Controller\Plugin\HybridAuth(), 792); $front->registerPlugin(new Controller\Plugin\QrCode(), 793); $front->registerPlugin(new Controller\Plugin\CommonFilesFilter(), 794); $front->registerPlugin(new Controller\Plugin\WysiwygAttributes(), 796); $front->registerPlugin(new Controller\Plugin\Webmastertools(), 797); $front->registerPlugin(new Controller\Plugin\Analytics(), 798); $front->registerPlugin(new Controller\Plugin\TagManagement(), 804); $front->registerPlugin(new Controller\Plugin\Targeting(), 805); $front->registerPlugin(new Controller\Plugin\EuCookieLawNotice(), 807); $front->registerPlugin(new Controller\Plugin\HttpErrorLog(), 850); $front->registerPlugin(new Controller\Plugin\Cache(), 901); // for caching } self::initControllerFront($front); // set router $router = $front->getRouter(); $routeAdmin = new \Zend_Controller_Router_Route('admin/:controller/:action/*', array('module' => 'admin', "controller" => "index", "action" => "index")); $routeInstall = new \Zend_Controller_Router_Route('install/:controller/:action/*', array('module' => 'install', "controller" => "index", "action" => "index")); $routeUpdate = new \Zend_Controller_Router_Route('admin/update/:controller/:action/*', array('module' => 'update', "controller" => "index", "action" => "index")); $routePlugins = new \Zend_Controller_Router_Route('admin/plugin/:controller/:action/*', array('module' => 'pluginadmin', "controller" => "index", "action" => "index")); $routeExtensions = new \Zend_Controller_Router_Route('admin/extensionmanager/:controller/:action/*', array('module' => 'extensionmanager', "controller" => "index", "action" => "index")); $routeReports = new \Zend_Controller_Router_Route('admin/reports/:controller/:action/*', array('module' => 'reports', "controller" => "index", "action" => "index")); $routePlugin = new \Zend_Controller_Router_Route('plugin/:module/:controller/:action/*', array("controller" => "index", "action" => "index")); $routeWebservice = new \Zend_Controller_Router_Route('webservice/:controller/:action/*', array("module" => "webservice", "controller" => "index", "action" => "index")); $routeSearchAdmin = new \Zend_Controller_Router_Route('admin/search/:controller/:action/*', array("module" => "searchadmin", "controller" => "index", "action" => "index")); // website route => custom router which check for a suitable document $routeFrontend = new Controller\Router\Route\Frontend(); $router->addRoute('default', $routeFrontend); // only do this if not frontend => performance issue if (!$frontend) { $router->addRoute("install", $routeInstall); $router->addRoute('plugin', $routePlugin); $router->addRoute('admin', $routeAdmin); $router->addRoute('update', $routeUpdate); $router->addRoute('plugins', $routePlugins); $router->addRoute('extensionmanager', $routeExtensions); $router->addRoute('reports', $routeReports); $router->addRoute('searchadmin', $routeSearchAdmin); if ($conf instanceof \Zend_Config and $conf->webservice and $conf->webservice->enabled) { $router->addRoute('webservice', $routeWebservice); } // check if this request routes into a plugin, if so check if the plugin is enabled if (preg_match("@^/plugin/([^/]+)/.*@", $_SERVER["REQUEST_URI"], $matches)) { $pluginName = $matches[1]; if (!Pimcore\ExtensionManager::isEnabled("plugin", $pluginName)) { \Pimcore\Tool::exitWithError("Plugin is disabled. To use this plugin please enable it in the extension manager!"); } } // force the main (default) domain for "admin" requests if ($conf->general->domain && $conf->general->domain != Tool::getHostname()) { $url = ($_SERVER['HTTPS'] == "on" ? "https" : "http") . "://" . $conf->general->domain . $_SERVER["REQUEST_URI"]; header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $url, true, 301); exit; } } // check if webdav is configured and add router if ($conf instanceof \Zend_Config) { if ($conf->assets->webdav->hostname) { $routeWebdav = new \Zend_Controller_Router_Route_Hostname($conf->assets->webdav->hostname, array("module" => "admin", 'controller' => 'asset', 'action' => 'webdav')); $router->addRoute('webdav', $routeWebdav); } } $front->setRouter($router); self::getEventManager()->trigger("system.startup", $front); // throw exceptions also when in preview or in editmode (documents) to see it immediately when there's a problem with this page $throwExceptions = false; if (Tool::isFrontentRequestByAdmin()) { $user = \Pimcore\Tool\Authentication::authenticateSession(); if ($user instanceof User) { $throwExceptions = true; } } // run dispatcher // this is also standard for /admin/ requests -> error handling is done in Pimcore_Controller_Action_Admin if (!PIMCORE_DEBUG && !$throwExceptions && !PIMCORE_DEVMODE) { @ini_set("display_errors", "Off"); @ini_set("display_startup_errors", "Off"); $front->dispatch(); } else { @ini_set("display_errors", "On"); @ini_set("display_startup_errors", "On"); $front->throwExceptions(true); try { $front->dispatch(); } catch (\Zend_Controller_Router_Exception $e) { if (!headers_sent()) { header("HTTP/1.0 404 Not Found"); } \Logger::err($e); throw new \Zend_Controller_Router_Exception("No route, document, custom route or redirect is matching the request: " . $_SERVER["REQUEST_URI"] . " | \n" . "Specific ERROR: " . $e->getMessage()); } catch (\Exception $e) { if (!headers_sent()) { header("HTTP/1.0 500 Internal Server Error"); } throw $e; } } }
<?php include dirname(__DIR__) . '/vendor/autoload.php'; use lithium\core\ErrorHandler; use Whoops\Run; use Whoops\Handler\PrettyPageHandler; ErrorHandler::apply('lithium\\action\\Dispatcher::run', array(), function ($info, $params) { $run = new Run(); $handler = new PrettyPageHandler(); $jsonHandler = new \Whoops\Handler\JsonResponseHandler(); $jsonHandler->onlyForAjaxRequests(true); $run->pushHandler($handler); $run->pushHandler($jsonHandler); $request = $params['request']; $exception = $info['exception']; $handler->addDataTable('Request', array('URL' => $request->url, 'Query String' => isset($request->params['query']) ? $request->params['query'] : '<none>', 'HTTP Host' => $request->get('http:host'), 'HTTP Method' => $request->get('http:method'), 'Base Path' => $request->path, 'Scheme' => $request->scheme, 'Port' => $request->port, 'Host' => $request->host, 'Auth' => $request->auth, 'Username' => $request->username, 'Password' => $request->password, 'Protocol' => $request->protocol, 'Version' => $request->version)); $handler->addDataTable('Params', $request->params); $handler->addDataTable('Data', $request->data); $handler->addDataTable('Headers', $request->headers); $handler->addDataTable('Cookies', $request->cookies); $handler->addDataTable('Body', $request->body); $run->writeToOutput(false); return $run->handleException($exception); });