本文整理汇总了PHP中Debugger::productionMode方法的典型用法代码示例。如果您正苦于以下问题:PHP Debugger::productionMode方法的具体用法?PHP Debugger::productionMode怎么用?PHP Debugger::productionMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Debugger
的用法示例。
在下文中一共展示了Debugger::productionMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enable
public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
{
error_reporting(E_ALL | E_STRICT);
if (is_bool($mode)) {
self::$productionMode = $mode;
} elseif (is_string($mode)) {
$mode = preg_split('#[,\\s]+#', "{$mode} 127.0.0.1 ::1");
}
if (is_array($mode)) {
self::$productionMode = !isset($_SERVER['REMOTE_ADDR']) || !in_array($_SERVER['REMOTE_ADDR'], $mode, TRUE);
}
if (self::$productionMode === self::DETECT) {
if (class_exists('Environment')) {
self::$productionMode = Environment::isProduction();
} elseif (isset($_SERVER['SERVER_ADDR']) || isset($_SERVER['LOCAL_ADDR'])) {
$addrs = array();
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$addrs = preg_split('#,\\s*#', $_SERVER['HTTP_X_FORWARDED_FOR']);
}
if (isset($_SERVER['REMOTE_ADDR'])) {
$addrs[] = $_SERVER['REMOTE_ADDR'];
}
$addrs[] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
self::$productionMode = FALSE;
foreach ($addrs as $addr) {
$oct = explode('.', $addr);
if ($addr !== '::1' && (count($oct) !== 4 || $oct[0] !== '10' && $oct[0] !== '127' && ($oct[0] !== '172' || $oct[1] < 16 || $oct[1] > 31) && ($oct[0] !== '169' || $oct[1] !== '254') && ($oct[0] !== '192' || $oct[1] !== '168'))) {
self::$productionMode = TRUE;
break;
}
}
} else {
self::$productionMode = !self::$consoleMode;
}
}
if (is_string($logDirectory)) {
self::$logDirectory = realpath($logDirectory);
if (self::$logDirectory === FALSE) {
throw new DirectoryNotFoundException("Directory '{$logDirectory}' is not found.");
}
} elseif ($logDirectory === FALSE) {
self::$logDirectory = FALSE;
} else {
self::$logDirectory = defined('APP_DIR') ? APP_DIR . '/../log' : getcwd() . '/log';
}
if (self::$logDirectory) {
ini_set('error_log', self::$logDirectory . '/php_error.log');
}
if (function_exists('ini_set')) {
ini_set('display_errors', !self::$productionMode);
ini_set('html_errors', FALSE);
ini_set('log_errors', FALSE);
} elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) {
throw new NotSupportedException('Function ini_set() must be enabled.');
}
if ($email) {
if (!is_string($email)) {
throw new InvalidArgumentException('Email address must be a string.');
}
self::$email = $email;
}
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}
if (!defined('E_USER_DEPRECATED')) {
define('E_USER_DEPRECATED', 16384);
}
if (!self::$enabled) {
register_shutdown_function(array(__CLASS__, '_shutdownHandler'));
set_exception_handler(array(__CLASS__, '_exceptionHandler'));
set_error_handler(array(__CLASS__, '_errorHandler'));
self::$enabled = TRUE;
}
}
示例2: enable
/**
* Enables displaying or logging errors and exceptions.
* @param mixed production, development mode, autodetection or IP address(es) whitelist.
* @param string error log directory; enables logging in production mode, FALSE means that logging is disabled
* @param string administrator email; enables email sending in production mode
* @return void
*/
public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
{
error_reporting(E_ALL | E_STRICT);
// production/development mode detection
if (is_bool($mode)) {
self::$productionMode = $mode;
} elseif ($mode !== self::DETECT || self::$productionMode === NULL) {
// IP addresses or computer names whitelist detection
$list = is_string($mode) ? preg_split('#[,\\s]+#', $mode) : (array) $mode;
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$list[] = '127.0.0.1';
$list[] = '::1';
}
self::$productionMode = !in_array(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'), $list, TRUE);
}
// logging configuration
if (is_string($logDirectory)) {
self::$logDirectory = realpath($logDirectory);
if (self::$logDirectory === FALSE) {
die(__METHOD__ . "() error: Log directory is not found or is not directory.");
}
} elseif ($logDirectory === FALSE) {
self::$logDirectory = FALSE;
} elseif (self::$logDirectory === NULL) {
self::$logDirectory = defined('APP_DIR') ? APP_DIR . '/../log' : getcwd() . '/log';
}
if (self::$logDirectory) {
ini_set('error_log', self::$logDirectory . '/php_error.log');
}
// php configuration
if (function_exists('ini_set')) {
ini_set('display_errors', !self::$productionMode);
// or 'stderr'
ini_set('html_errors', FALSE);
ini_set('log_errors', FALSE);
} elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) {
// intentionally ==
die(__METHOD__ . "() error: Unable to set 'display_errors' because function ini_set() is disabled.");
}
if ($email) {
if (!is_string($email)) {
die(__METHOD__ . '() error: Email address must be a string.');
}
self::$email = $email;
}
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}
if (!defined('E_USER_WARNING')) {
define('E_USER_WARNING', 16384);
}
if (!self::$enabled) {
register_shutdown_function(array(__CLASS__, '_shutdownHandler'));
set_exception_handler(array(__CLASS__, '_exceptionHandler'));
set_error_handler(array(__CLASS__, '_errorHandler'));
self::$enabled = TRUE;
}
}