/** Bootstrap code @public **/ static function start() { // Prohibit multiple calls if (self::$vars) { return; } // Handle all exceptions/non-fatal errors error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 0); ini_set('register_globals', 0); // Get PHP settings $ini = ini_get_all(NULL, FALSE); // Intercept errors and send output to browser set_error_handler(function ($errno, $errstr) { if (error_reporting()) { // Error suppression (@) is not enabled $self = __CLASS__; $self::error(500, $errstr); } }); // Do the same for PHP exceptions set_exception_handler(function ($ex) { if (!count($trace = $ex->getTrace())) { // Translate exception trace list($trace) = debug_backtrace(); $arg = $trace['args'][0]; $trace = array(array('file' => $arg->getFile(), 'line' => $arg->getLine(), 'function' => '{main}', 'args' => array())); } $self = __CLASS__; $self::error(500, $ex->getMessage(), $trace); // PHP aborts at this point }); // Apache mod_rewrite enabled? if (function_exists('apache_get_modules') && !in_array('mod_rewrite', apache_get_modules())) { trigger_error(self::TEXT_Apache); return; } // Fix Apache's VirtualDocumentRoot limitation $_SERVER['DOCUMENT_ROOT'] = dirname(self::fixslashes($_SERVER['SCRIPT_FILENAME'])); // Adjust HTTP request time precision $_SERVER['REQUEST_TIME'] = microtime(TRUE); // Hydrate framework variables $base = self::fixslashes(preg_replace('/\\/[^\\/]+$/', '', $_SERVER['SCRIPT_NAME'])); $scheme = PHP_SAPI == 'cli' ? NULL : isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ? 'https' : 'http'; $jar = array('expire' => 0, 'path' => $base ?: '/', 'domain' => '.' . $_SERVER['SERVER_NAME'], 'secure' => $scheme == 'https', 'httponly' => TRUE); self::$vars = array('AUTOLOAD' => './', 'BASE' => $base, 'CACHE' => FALSE, 'DEBUG' => 1, 'DNSBL' => NULL, 'ENCODING' => 'utf-8', 'ERROR' => NULL, 'EXTEND' => TRUE, 'EXEMPT' => NULL, 'GUI' => './', 'HOTLINK' => NULL, 'IMPORTS' => './', 'JAR' => $jar, 'LANGUAGE' => NULL, 'LOADED' => NULL, 'LOCALES' => './', 'MAXSIZE' => self::bytes($ini['post_max_size']), 'MUTEX' => 60, 'ONERROR' => NULL, 'PLUGINS' => self::fixslashes(__DIR__) . '/', 'PROTOCOL' => $scheme, 'PROXY' => FALSE, 'PUT' => NULL, 'QUIET' => FALSE, 'ROOT' => $_SERVER['DOCUMENT_ROOT'] . '/', 'ROUTES' => NULL, 'SPAM' => NULL, 'STRICT' => TRUE, 'STATS' => array('MEMORY' => array('start' => memory_get_usage()), 'TIME' => array('start' => microtime(TRUE))), 'TEMP' => 'temp/', 'THROTTLE' => 0, 'TIDY' => array(), 'VERSION' => self::TEXT_AppName . ' ' . self::TEXT_Version, 'WHOIS' => 'whois.internic.net'); // Alias the GUI variable (2.0+) self::$vars['UI'] =& self::$vars['GUI']; // Create convenience containers for PHP globals foreach (explode('|', self::PHP_Globals) as $var) { // Sync framework and PHP globals self::$vars[$var] =& $GLOBALS['_' . $var]; if (isset($ini['magic_quotes_gpc']) && $ini['magic_quotes_gpc'] && preg_match('/^[GPCR]/', $var)) { // Corrective action on PHP magic quotes array_walk_recursive(self::$vars[$var], function (&$val) { $val = stripslashes($val); }); } } if (PHP_SAPI == 'cli') { // Command line: Parse GET variables in URL, if any if (isset($_SERVER['argc']) && $_SERVER['argc'] < 2) { array_push($_SERVER['argv'], '/'); } // Detect host name from environment $_SERVER['SERVER_NAME'] = gethostname(); // Convert URI to human-readable string self::mock('GET ' . $_SERVER['argv'][1]); } // Initialize autoload stack and shutdown sequence spl_autoload_register(__CLASS__ . '::autoload'); register_shutdown_function(__CLASS__ . '::stop'); }