public function resetHandlers() { $grav = Grav::instance(); $config = $grav['config']->get('system.errors'); $jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json'; // Setup Whoops-based error handler $whoops = new \Whoops\Run(); $verbosity = 1; if (isset($config['display'])) { if (is_int($config['display'])) { $verbosity = $config['display']; } else { $verbosity = $config['display'] ? 1 : 0; } } switch ($verbosity) { case 1: $error_page = new Whoops\Handler\PrettyPageHandler(); $error_page->setPageTitle('Crikey! There was an error...'); $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); $error_page->addCustomCss('whoops.css'); $whoops->pushHandler($error_page); break; case -1: $whoops->pushHandler(new BareHandler()); break; default: $whoops->pushHandler(new SimplePageHandler()); break; } if (method_exists('Whoops\\Util\\Misc', 'isAjaxRequest')) { //Whoops 2.0 if (Whoops\Util\Misc::isAjaxRequest() || $jsonRequest) { $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } } elseif (function_exists('Whoops\\isAjaxRequest')) { //Whoops 2.0.0-alpha if (Whoops\isAjaxRequest() || $jsonRequest) { $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } } else { //Whoops 1.x $json_page = new Whoops\Handler\JsonResponseHandler(); $json_page->onlyForAjaxRequests(true); } if (isset($config['log']) && $config['log']) { $logger = $grav['log']; $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { try { $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString()); } catch (\Exception $e) { echo $e; } }, 'log'); } $whoops->register(); }
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(); }
public function register(Container $app) { if (!$app['config']->get('app.debug')) { return false; } $run = new Run(); $handler = new PrettyPageHandler(); // Set the title of the error page: $handler->setPageTitle('Whoops! There was a problem.'); $run->pushHandler($handler); if (Misc::isAjaxRequest() || $app['is_api_request']) { $run->pushHandler(new JsonResponseHandler()); } // Register the handler with PHP, and you're set! $run->register(); }
/** * @param DI $di */ public function __construct(DI $di = null) { if (!$di) { $di = DI::getDefault(); } // There's only ever going to be one error page...right? $di->setShared('whoops.pretty_page_handler', function () { return new PrettyPageHandler(); }); // There's only ever going to be one error page...right? $di->setShared('whoops.json_response_handler', function () { $jsonHandler = new JsonResponseHandler(); return $jsonHandler; }); // Retrieves info on the Phalcon environment and ships it off // to the PrettyPageHandler's data tables: // This works by adding a new handler to the stack that runs // before the error page, retrieving the shared page handler // instance, and working with it to add new data tables $phalcon_info_handler = function () use($di) { try { $request = $di['request']; } catch (Exception $e) { // This error occurred too early in the application's life // and the request instance is not yet available. return; } // Request info: $di['whoops.pretty_page_handler']->addDataTable('Phalcon Application (Request)', array('URI' => $request->getScheme() . '://' . $request->getServer('HTTP_HOST') . $request->getServer('REQUEST_URI'), 'Request URI' => $request->getServer('REQUEST_URI'), 'Path Info' => $request->getServer('PATH_INFO'), 'Query String' => $request->getServer('QUERY_STRING') ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getServer('SCRIPT_NAME'), 'Scheme' => $request->getScheme(), 'Port' => $request->getServer('SERVER_PORT'), 'Host' => $request->getServerName())); }; $di->setShared('whoops', function () use($di, $phalcon_info_handler) { $run = new Run(); $run->pushHandler($di['whoops.pretty_page_handler']); $run->pushHandler($phalcon_info_handler); if (\Whoops\Util\Misc::isAjaxRequest()) { $run->pushHandler($di['whoops.json_response_handler']); } return $run; }); $di['whoops']->register(); }
/** * If configuration indicates a JsonResponseHandler, configure and register it. * * @param Whoops $whoops * @param array|\ArrayAccess $config */ private function registerJsonHandler(Whoops $whoops, $config) { if (!isset($config['json_exceptions']['display']) || empty($config['json_exceptions']['display'])) { return; } $handler = new JsonResponseHandler(); if (isset($config['json_exceptions']['show_trace'])) { $handler->addTraceToOutput(true); } if (isset($config['json_exceptions']['ajax_only'])) { if (method_exists(\Whoops\Util\Misc::class, 'isAjaxRequest')) { // Whoops 2.x if (!\Whoops\Util\Misc::isAjaxRequest()) { return; } } elseif (method_exists($handler, 'onlyForAjaxRequests')) { // Whoops 1.x $handler->onlyForAjaxRequests(true); } } $whoops->pushHandler($handler); }
/** * Constructor. * * @param array $configs * * @since 0.0.6 */ public function __construct($configs = []) { // Use Whoops vendor to display errors $run = new Run(); // New Pretty handler $handler = new PrettyPageHandler(); // Custom tables if (!empty($configs)) { $handler->addDataTable('Olympus configurations', $configs); } // Page title $handler->setPageTitle('Whoops! There was a problem.'); // Page custom CSS $handler->setResourcesPath(WEBPATH . 'resources' . S . 'whoops' . S); $handler->addCustomCss('olympoops.base.css'); // Push all in handler $run->pushHandler($handler); // AJAX requests if (Misc::isAjaxRequest()) { $run->pushHandler(new JsonResponseHandler()); } // Handler registration $run->register(); }
use Themosis\Configuration\Support; use Themosis\Configuration\Template; use Themosis\Core\AdminLoader; use Themosis\Core\WidgetLoader; use Themosis\Facades\Config; $run = new \Whoops\Run(); $handler = new \Whoops\Handler\PrettyPageHandler(); // Set the title of the error page: $handler->setPageTitle("Whoops! There was a problem."); $run->pushHandler($handler); // Add a special handler to deal with AJAX requests with an // equally-informative JSON response. Since this handler is // first in the stack, it will be executed before the error // page handler, and will have a chance to decide if anything // needs to be done. if (\Whoops\Util\Misc::isAjaxRequest()) { $run->pushHandler(new \Whoops\Handler\JsonResponseHandler()); } // Register the handler with PHP, and you're set! $run->register(); /*----------------------------------------------------*/ // Set theme's configurations. /*----------------------------------------------------*/ // Load the theme configuration files. add_filter('themosisConfigPaths', function ($paths) { $paths[] = themosis_path('theme') . 'config' . DS; return $paths; }); /*----------------------------------------------------*/ // Autoload theme classes. /*----------------------------------------------------*/
/** * @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()); if (\Whoops\Util\Misc::isAjaxRequest()) { $jsonErrorHandler = new \Whoops\Handler\JsonResponseHandler(); $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); } 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\GoogleTagManager(), 810); $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; } } $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; } } }
* * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================ */ use Opis\Colibri\Application; use Whoops\Run as WhoopsRun; use Whoops\Handler\JsonResponseHandler; use Whoops\Handler\PrettyPageHandler; use Whoops\Handler\PlainTextHandler; use Whoops\Util\Misc; error_reporting(-1); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('opcache.enable', 0); $loader = (require_once 'vendor/autoload.php'); if (getenv('APP_PRODUCTION') === false) { $whoops = new WhoopsRun(); if (Misc::isCommandLine()) { $whoops->pushHandler(new PlainTextHandler()); } elseif (Misc::isAjaxRequest()) { $whoops->pushHandler(new JsonResponseHandler()); } else { $whoops->pushHandler(new PrettyPageHandler()); } $whoops->register(); } $app = new Application(__DIR__, $loader); return $app->bootstrap();