Beispiel #1
0
 /**
  * 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;
     }
 }