/** * 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; } }
/** * 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; } }
/** * 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(); }
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; } }