本文整理汇总了PHP中Whoops\Util\Misc类的典型用法代码示例。如果您正苦于以下问题:PHP Misc类的具体用法?PHP Misc怎么用?PHP Misc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Misc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
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;
}
示例2: handle
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;
}
示例3: handle
/**
* @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;
}
示例4: resetHandlers
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();
}
示例5: handle
/**
* @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;
}
示例6: handle
/**
* @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;
}
示例7: handle
/**
* @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;
}
示例8: run
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();
}
示例9: handle
/**
* @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;
}
示例10: register
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();
}
示例11: init
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();
}
}
示例12: 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();
}
示例13: 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;
}
示例14: __construct
/**
* @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();
}
示例15: handle
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;
}