public function handle() { if (!$this->isAjaxRequest()) { return Handler::DONE; } $display = Config::get('concrete.debug.display_errors'); if (!$display) { $error = array('message' => t('An error occurred while processing this request.')); } else { $detail = Config::get('concrete.debug.detail', 'message'); if ($detail !== 'debug') { $e = $this->getInspector()->getException(); $error = array('message' => $e->getMessage()); } else { $error = Formatter::formatExceptionAsDataArray($this->getInspector(), true); } } $response = array('error' => $error, 'errors' => array($error['message'])); if (Misc::canSendHeaders()) { if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { header('Content-Type: application/json; charset=' . APP_CHARSET, true); } else { header('Content-Type: text/plain; charset=' . APP_CHARSET, true); } } echo json_encode($response); return Handler::QUIT; }
public function handle() { if (!$this->isAjaxRequest()) { return Handler::DONE; } $ex = $this->getException(); if ($ex instanceof UserException) { $obj = ['message' => $ex->getMessage(), 'code' => $ex->getUserErrorCode(), 'status' => $ex->getCode()]; } else { if ($this->debug) { $obj = ['message' => $ex->getMessage(), 'code' => $ex->getCode(), 'status' => 500]; } else { $obj = ['message' => 'Server internal error', 'code' => -1, 'status' => 500]; } } if ($this->debug) { $obj['detail'] = Formatter::formatExceptionAsDataArray($this->getInspector(), true); } $this->getRun()->sendHttpCode($obj['status']); if (Misc::canSendHeaders()) { header('Content-Type: application/json'); } echo json_encode($obj); return Handler::QUIT; }
/** * @return int|null */ public function handle() { if (!$this->handleUnconditionally()) { // Check conditions for outputting HTML: // @todo: Make this more robust if (php_sapi_name() === 'cli') { // Help users who have been relying on an internal test value // fix their code to the proper method if (isset($_ENV['whoops-test'])) { throw new \Exception('Use handleUnconditionally instead of whoops-test' . ' environment variable'); } return Handler::DONE; } } $exception = func_get_arg(0); // @todo: Make this more dynamic $helper = new TemplateHelper(); $templateFile = $this->getResource("views/layout.html.php"); $cssFile = $this->getResource("css/whoops.base.css"); $zeptoFile = $this->getResource("js/zepto.min.js"); $jsFile = $this->getResource("js/whoops.base.js"); if ($this->customCss) { $customCssFile = $this->getResource($this->customCss); } $inspector = $this->getInspector(); $frames = $inspector->getFrames(); $code = $inspector->getException()->getCode(); if ($inspector->getException() instanceof \ErrorException) { // ErrorExceptions wrap the php-error types within the "severity" property $code = Misc::translateErrorCode($inspector->getException()->getSeverity()); } // List of variables that will be passed to the layout template. $vars = array("page_title" => $this->getPageTitle(), "stylesheet" => file_get_contents($cssFile), "zepto" => file_get_contents($zeptoFile), "javascript" => file_get_contents($jsFile), "header" => $this->getResource("views/header.html.php"), "frame_list" => $this->getResource("views/frame_list.html.php"), "frame_code" => $this->getResource("views/frame_code.html.php"), "env_details" => $this->getResource("views/env_details.html.php"), "title" => $this->getPageTitle(), "name" => explode("\\", $inspector->getExceptionName()), "message" => $inspector->getException()->getMessage(), "code" => $code, "plain_exception" => Formatter::formatExceptionPlain($inspector), "frames" => $frames, "has_frames" => !!count($frames), "handler" => $this, "handlers" => $this->getRun()->getHandlers(), "tables" => array("Server/Request Data" => $_SERVER, "GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Environment Variables" => $_ENV)); if (isset($customCssFile)) { $vars["stylesheet"] .= file_get_contents($customCssFile); } // Add extra entries list of data tables: // @todo: Consolidate addDataTable and addDataTableCallback $extraTables = array_map(function ($table) { return $table instanceof \Closure ? $table() : $table; }, $this->getDataTables()); $vars["tables"] = array_merge($extraTables, $vars["tables"]); $helper->setVariables($vars); ob_start(); $helper->render($templateFile); $content = ob_get_clean(); $pathMatches = (bool) preg_match('/phalcon-debugbar/', $exception->getFile()); if (is_object($this->di) && !$pathMatches) { try { $response = $this->di['response']->setContent($content); $response = $this->di['debugbar']->modifyResponse($response); $content = $response->getContent(); } catch (\Exception $e) { } } echo $content; return Handler::QUIT; }
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(); }
/** * @return int */ public function handle() { $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: application/json'); } echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0); return Handler::QUIT; }
/** * @return int */ public function handle() { if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { return Handler::DONE; } $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: application/json'); } echo json_encode($response); return Handler::QUIT; }
/** * @return int */ public function handle() { if (!$this->isAjaxRequest()) { return Handler::DONE; } $response = array('success' => false, 'data' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); if (Misc::canSendHeaders()) { header('Content-Type: application/json; charset=' . get_option('blog_charset')); } $json_options = version_compare(PHP_VERSION, '5.4.0', '>=') ? JSON_PRETTY_PRINT : 0; echo wp_json_encode($response, $json_options); return Handler::QUIT; }
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(); }
/** * @return int|null */ public function handle() { $inspector = $this->getInspector(); $helper = new TemplateHelper(); $templateFile = $this->getResource("layout.html.php"); $cssFile = $this->getResource("error.css"); $code = $inspector->getException()->getCode(); if ($inspector->getException() instanceof \ErrorException) { $code = Misc::translateErrorCode($code); } $vars = array("stylesheet" => file_get_contents($cssFile), "code" => $code); $helper->setVariables($vars); $helper->render($templateFile); return Handler::QUIT; }
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(); }
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(); } }
public function register() { if (function_exists('ini_set')) { ini_set('display_errors', 0); } $run = new Run(); $handler = new ErrorHandler(); $run->pushHandler($handler); $json_handler = new JsonErrorHandler(); $run->pushHandler($json_handler); if (Misc::isCommandLine()) { $cli_handler = new PlainTextHandler(); $cli_handler->addTraceFunctionArgsToOutput(true); $cli_handler->addTraceToOutput(true); $run->pushHandler($cli_handler); } $run->register(); }
/** * @return int */ public function handle() { if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { return \Whoops\Handler\Handler::DONE; } if ($this->onlyForJsonRequests() && !$this->isJsonRequest()) { return \Whoops\Handler\Handler::DONE; } $response = array('error' => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput())); unset($response['error']['file']); unset($response['error']['line']); $response['error']['code'] = $this->getException()->getCode(); if (\Whoops\Util\Misc::canSendHeaders()) { http_response_code($response['error']['code']); header('Content-Type: application/json'); } echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0); return \Whoops\Handler\Handler::QUIT; }
/** * @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(); }
public function handle() { $debug = Config::get('concrete.debug.level', 0); if ($debug !== DEBUG_DISPLAY_ERRORS) { return Handler::DONE; } if (!$this->isAjaxRequest()) { return Handler::DONE; } $error = Formatter::formatExceptionAsDataArray($this->getInspector(), true); $response = array('error' => $error, 'errors' => array($error['message'])); if (\Whoops\Util\Misc::canSendHeaders()) { if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { header('Content-Type: application/json; charset=' . APP_CHARSET, true); } else { header('Content-Type: text/plain; charset=' . APP_CHARSET, true); } } echo json_encode($response); return Handler::QUIT; }
/** * 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(); }
/** * Echo something to the browser * @param string $output * @return $this */ private function writeToOutputNow($output) { if ($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) { $httpCode = $this->sendHttpCode(); if (function_exists('http_response_code')) { http_response_code($httpCode); } else { // http_response_code is added in 5.4. // For compatibility with 5.3 we use the third argument in header call // First argument must be a real header. // If it is empty, PHP will ignore the third argument. // If it is invalid, such as a single space, Apache will handle it well, // but the PHP development server will hang. // Setting a full status line would require us to hardcode // string values for all different status code, and detect the protocol. // which is an extra error-prone complexity. header('X-Ignore-This: 1', true, $httpCode); } } echo $output; return $this; }
/** * @return int */ public function handle() { if (!$this->canProcess()) { return Handler::DONE; } $exception = $this->getException(); $response = sprintf("%s: %s in file %s on line %d%s\n", get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $this->getTraceOutput()); if ($this->getLogger()) { $this->getLogger()->error($response); } if (!$this->canOutput()) { return Handler::DONE; } if (class_exists('\\Whoops\\Util\\Misc') && \Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: text/plain'); } echo $response; return Handler::QUIT; }
/** * @return int */ public function handle() { $response = $this->generateResponse(); if ($this->getLogger()) { $this->getLogger()->error($response); } if (!$this->canOutput()) { return Handler::DONE; } if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: text/plain'); } echo $response; return Handler::QUIT; }
/** * @return int */ public function handle() { if (!$this->canProcess()) { return Handler::DONE; } $exception = $this->getException(); // $response = sprintf("%s: %s in file %s on line %d%s\n", // get_class($exception), // $exception->getMessage(), // $exception->getFile(), // $exception->getLine(), // // $this->getTraceOutput() // null // ); //var_dump($exception); // echo "1"; if ($this->getLogger()) { $this->getLogger()->error($response); } if (!is_null($exception)) { $msg = $this->msg; $bg_color = $this->bg_color; include_once '../core/Access/ErrorDisplayer/simple.php'; } return Handler::QUIT; if (!$this->canOutput()) { return Handler::DONE; } if (class_exists('\\Whoops\\Util\\Misc') && \Whoops\Util\Misc::canSendHeaders()) { //header('Content-Type: html/text'); } //if(! is_null ($exception)) echo "fff"; return Handler::QUIT; }
/** * Echo something to the browser * @param string $output * @return $this */ private function writeToOutputNow($output) { if ($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) { $this->system->setHttpResponseCode($this->sendHttpCode()); } echo $output; return $this; }
/** * @return int */ public function handle() { if (!$this->canProcess()) { return Handler::DONE; } $exception = $this->getException(); // $response = sprintf("%s: %s in file %s on line %d%s\n", // get_class($exception), // $exception->getMessage(), // $exception->getFile(), // $exception->getLine(), // // $this->getTraceOutput() // null // ); //var_dump($exception); // echo "1"; if ($this->getLogger()) { $this->getLogger()->error($response); } if (!is_null($exception)) { $msg = $this->msg; $bg_color = $this->bg_color; //include_once '/core/Access/ErrorDisplayer/simple.php'; ?> <head> <meta charset="utf-8"/> <title><?php echo $msg; ?> </title> <style type="text/css"> body { background: #e9e9e9; background: <?php echo $bg_color; ?> ; margin: 0px; padding: 0px; } div { box-shadow: 0px 3px 6px 3px rgba(0,0,0,0.2); border:1px solid gray; border-radius:5px; display: inline-block; padding:30px; font-size: 16px; font: 20px Georgia, "Times New Roman", Times, serif; width: 460px; margin: 60px auto; display: block; background: white; } </style> </head> <body> <div><?php echo $msg; ?> </div> </body> <?php } return Handler::QUIT; if (!$this->canOutput()) { return Handler::DONE; } if (class_exists('\\Whoops\\Util\\Misc') && \Whoops\Util\Misc::canSendHeaders()) { //header('Content-Type: html/text'); } //if(! is_null ($exception)) echo "fff"; return Handler::QUIT; }
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. /*----------------------------------------------------*/
/** * @return int|null */ public function handle() { if (!$this->handleUnconditionally()) { // Check conditions for outputting HTML: // @todo: Make this more robust if (php_sapi_name() === 'cli') { // Help users who have been relying on an internal test value // fix their code to the proper method if (isset($_ENV['whoops-test'])) { throw new \Exception('Use handleUnconditionally instead of whoops-test' . ' environment variable'); } return Handler::DONE; } } // @todo: Make this more dynamic $helper = new TemplateHelper(); $cloner = new VarCloner(); // Only dump object internals if a custom caster exists. $cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) { $class = $stub->class; $classes = [$class => $class] + class_parents($class) + class_implements($class); foreach ($classes as $class) { if (isset(AbstractCloner::$defaultCasters[$class])) { return $a; } } // Remove all internals return []; }]); $helper->setCloner($cloner); $templateFile = $this->getResource("views/layout.html.php"); $cssFile = $this->getResource("css/whoops.base.css"); $zeptoFile = $this->getResource("js/zepto.min.js"); $clipboard = $this->getResource("js/clipboard.min.js"); $jsFile = $this->getResource("js/whoops.base.js"); if ($this->customCss) { $customCssFile = $this->getResource($this->customCss); } $inspector = $this->getInspector(); $frames = $inspector->getFrames(); $code = $inspector->getException()->getCode(); if ($inspector->getException() instanceof \ErrorException) { // ErrorExceptions wrap the php-error types within the "severity" property $code = Misc::translateErrorCode($inspector->getException()->getSeverity()); } // List of variables that will be passed to the layout template. $vars = array("page_title" => $this->getPageTitle(), "stylesheet" => file_get_contents($cssFile), "zepto" => file_get_contents($zeptoFile), "clipboard" => file_get_contents($clipboard), "javascript" => file_get_contents($jsFile), "header" => $this->getResource("views/header.html.php"), "frame_list" => $this->getResource("views/frame_list.html.php"), "frame_code" => $this->getResource("views/frame_code.html.php"), "env_details" => $this->getResource("views/env_details.html.php"), "title" => $this->getPageTitle(), "name" => explode("\\", $inspector->getExceptionName()), "message" => $inspector->getException()->getMessage(), "code" => $code, "plain_exception" => Formatter::formatExceptionPlain($inspector), "frames" => $frames, "has_frames" => !!count($frames), "handler" => $this, "handlers" => $this->getRun()->getHandlers(), "tables" => array("GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Server/Request Data" => $_SERVER, "Environment Variables" => $_ENV)); if (isset($customCssFile)) { $vars["stylesheet"] .= file_get_contents($customCssFile); } // Add extra entries list of data tables: // @todo: Consolidate addDataTable and addDataTableCallback $extraTables = array_map(function ($table) { return $table instanceof \Closure ? $table() : $table; }, $this->getDataTables()); $vars["tables"] = array_merge($extraTables, $vars["tables"]); if (\Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: text/html'); } $helper->setVariables($vars); $helper->render($templateFile); return Handler::QUIT; }
/** * Gets the backgrace from an exception. * * If xdebug is installed * * @param Exception $e * @return array */ protected function getTrace(\Exception $e) { $traces = $e->getTrace(); // Get trace from xdebug if enabled, failure exceptions only trace to the shutdown handler by default if (!$e instanceof \ErrorException) { return $traces; } if (!Misc::isLevelFatal($e->getSeverity())) { return $traces; } if (!extension_loaded('xdebug') || !xdebug_is_enabled()) { return array(); } // Use xdebug to get the full stack trace and remove the shutdown handler stack trace $stack = array_reverse(xdebug_get_function_stack()); $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $traces = array_diff_key($stack, $trace); return $traces; }
* * 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();
/** * @dataProvider provideTranslateException * @param string $expected_output * @param int $exception_code */ public function testTranslateException($expected_output, $exception_code) { $output = Misc::translateErrorCode($exception_code); $this->assertEquals($expected_output, $output); }
/** * @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; } } }