php Whoops-Util-Misc类(方法)实例源码

下面列出了php Whoops-Util-Misc 类(方法)源码代码实例,从而了解它的用法。

作者:cek    项目:concrete5-   
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;
 }

作者:Tanklon    项目:openv   
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;
 }

作者:minhlaole    项目:phalcon-debugba   
/**
  * @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;
 }

作者:indigo42    项目:blog.no42.or   
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();
 }

作者:ema    项目:emacoo.c   
/**
  * @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;
 }

作者:anthrotec    项目:laravel_sampl   
/**
  * @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;
 }

作者:rars    项目:wp   
/**
  * @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;
 }

作者:y80x86o    项目:simpla-framewor   
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();
 }

作者:loci    项目:corporation-documentatio   
/**
  * @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;
 }

作者:speedwor    项目:provide   
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();
 }

作者:mermetb    项目:biom   
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();
     }
 }

作者:ppiedaderawne    项目:concrete   
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();
 }

作者:riktamtec    项目:zf2-error-handle   
/**
  * @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;
 }

作者:denners77    项目:api-phalco   
/**
  * @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();
 }

作者:meixelsberge    项目:concrete5-5.7.   
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;
 }

作者:zendframewor    项目:zend-expressiv   
/**
  * 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);
 }

作者:GetOlympu    项目:Olympu   
/**
  * 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();
 }

作者:jeremycherfa    项目:grav-blo   
/**
  * 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;
 }

作者:anthrotec    项目:laravel_sampl   
/**
  * @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;
 }

作者:indigo42    项目:blog.no42.or   
/**
  * @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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号