本文整理汇总了PHP中Environment::getMode方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getMode方法的具体用法?PHP Environment::getMode怎么用?PHP Environment::getMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::getMode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: detect
/**
* Detect environment mode.
* @param string mode name
* @return bool
*/
public function detect($name)
{
switch ($name) {
case 'environment':
// environment name autodetection
if ($this->detect('console')) {
return Environment::CONSOLE;
} else {
return Environment::getMode('live') ? Environment::PRODUCTION : Environment::DEVELOPMENT;
}
case 'live':
// detects production mode by server IP address
if (PHP_SAPI === 'cli') {
return FALSE;
} elseif (isset($_SERVER['SERVER_ADDR'])) {
$oct = explode('.', $_SERVER['SERVER_ADDR']);
return count($oct) !== 4 || $oct[0] !== '10' && $oct[0] !== '127' && ($oct[0] !== '171' || $oct[1] < 16 || $oct[1] > 31) && ($oct[0] !== '169' || $oct[1] !== '254') && ($oct[0] !== '192' || $oct[1] !== '168');
} else {
return TRUE;
}
case 'debug':
// Determines whether the debugger is active
if (defined('DEBUG_MODE')) {
return (bool) DEBUG_MODE;
} else {
return !Environment::getMode('live') && isset($_REQUEST['DBGSESSID']);
// function_exists('DebugBreak');
}
case 'console':
return PHP_SAPI === 'cli';
default:
// unknown mode
return NULL;
}
}
示例2: detect
/**
* Detect environment mode.
* @param string mode name
* @return bool
*/
public function detect($name)
{
switch ($name) {
case 'environment':
// environment name autodetection
if ($this->detect('console')) {
return Environment::CONSOLE;
} else {
return Environment::getMode('production') ? Environment::PRODUCTION : Environment::DEVELOPMENT;
}
case 'production':
// detects production mode by server IP address
if (PHP_SAPI === 'cli') {
return FALSE;
} elseif (isset($_SERVER['SERVER_ADDR']) || isset($_SERVER['LOCAL_ADDR'])) {
$addr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
$oct = explode('.', $addr);
// 10.0.0.0/8 Private network
// 127.0.0.0/8 Loopback
// 169.254.0.0/16 & ::1 Link-Local
// 172.16.0.0/12 Private network
// 192.168.0.0/16 Private network
return $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'));
} else {
return TRUE;
}
case 'console':
return PHP_SAPI === 'cli';
default:
// unknown mode
return NULL;
}
}
示例3: run
/**
* Dispatch an HTTP request to a routing debugger. Please don't call directly.
*/
public static function run()
{
if (!self::$enabled || Environment::getMode('production')) {
return;
}
self::$enabled = FALSE;
$debugger = new self(Environment::getApplication()->getRouter(), Environment::getHttpRequest());
$debugger->paint();
}
示例4: detect
function detect($name)
{
switch ($name) {
case 'environment':
if ($this->detect('console')) {
return Environment::CONSOLE;
} else {
return Environment::getMode('production') ? Environment::PRODUCTION : Environment::DEVELOPMENT;
}
case 'production':
if (PHP_SAPI === 'cli') {
return FALSE;
} elseif (isset($_SERVER['SERVER_ADDR']) || isset($_SERVER['LOCAL_ADDR'])) {
$addr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
$oct = explode('.', $addr);
return $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'));
} else {
return TRUE;
}
case 'console':
return PHP_SAPI === 'cli';
default:
return NULL;
}
}