private static function autoEnvironment() { if (php_sapi_name() === 'cli') { return 'development'; } // A simple “Host:” header is one that does not have a TLD or whose TLD is one of local, home, or xip.io or coincides with the listening address (meaning it’s addressed by IP only). $bSimpleHost = false; if (isset($_SERVER['HTTP_HOST'])) { // As it’s simple HTTP header, this could be easily faked by the client but then this installation would be reachable by plain HTTP 1.0, which modern setups (vhosts) aren’t. $bSimpleHost = strpos($_SERVER['HTTP_HOST'], '.') === false; if (!$bSimpleHost) { $sTLD = explode('.', $_SERVER['HTTP_HOST']); $sTLD = array_pop($sTLD); $bSimpleHost = in_array($sTLD, array('local', 'home')) || StringUtil::endsWith($_SERVER['HTTP_HOST'], '.xip.io'); } if (!$bSimpleHost && isset($_SERVER['SERVER_ADDR'])) { $bSimpleHost = $_SERVER['HTTP_HOST'] === $_SERVER['SERVER_ADDR']; } } // A simple server is defined as one that listens only on loopback or whose listening address coincides with the client address (CAUTION: may also be true on reverse-proxy environments) $bSimpleServer = false; if (isset($_SERVER['SERVER_ADDR'])) { $bSimpleServer = $_SERVER['SERVER_ADDR'] === '127.0.0.1' || $_SERVER['SERVER_ADDR'] === '::1'; if (!$bSimpleServer && isset($_SERVER['REMOTE_ADDR'])) { $bSimpleServer = $_SERVER['SERVER_ADDR'] === $_SERVER['REMOTE_ADDR']; } } if ($bSimpleHost && $bSimpleServer) { return 'development'; } // A test host is one whose host name starts is on one of the following subdomains: test, stage, staging, integration $bTestHost = false; if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], '.') !== false) { $sSubDomain = explode('.', $_SERVER['HTTP_HOST']); $sSubDomain = $sSubDomain[0]; $bTestHost = in_array($sSubDomain, array('test', 'stage', 'staging', 'integration')); } if ($bTestHost) { return 'staging'; } ErrorHandler::log("WARNING: RAPILA_ENVIRONMENT autodetection found “production”. Please configure manually if really a production environment."); return 'production'; }
/** * Exception handler * * @param Exception $e */ public static function logException(\Exception $e) { $message = "Exception " . get_class($e) . " from " . $e->getFile() . " in line " . $e->getLine() . " : " . $e->getMessage(); ErrorHandler::log($message, $e->getMessage()); }
public static function setLogSettings($use, $type = ErrorHandler::LOG_SYSTEM, $destination = 'php_error.log') { self::$log = $use; self::$log_type = $type; self::$log_destination = $destination; }