function __construct()
{
// Managed directives
ini_set('default_charset', $charset = 'UTF-8');
if (extension_loaded('mbstring')) {
mb_internal_encoding($charset);
}
ini_set('display_errors', 0);
// Deprecated directives
@ini_set('magic_quotes_gpc', 0);
@ini_set('register_globals', 0);
// Intercept errors/exceptions; PHP5.3-compatible
$check = error_reporting((E_ALL | E_STRICT) & ~(E_NOTICE | E_USER_NOTICE));
$fw = $this;
set_exception_handler(function ($obj) use($fw) {
$fw->hive['EXCEPTION'] = $obj;
$fw->error(500, $obj->getmessage() . ' ' . '[' . $obj->getFile() . ':' . $obj->getLine() . ']', $obj->gettrace());
});
set_error_handler(function ($level, $text) use($fw) {
if ($level & error_reporting()) {
$fw->error(500, $text, NULL, $level);
}
});
if (!isset($_SERVER['SERVER_NAME'])) {
$_SERVER['SERVER_NAME'] = gethostname();
}
if ($cli = PHP_SAPI == 'cli') {
// Emulate HTTP request
$_SERVER['REQUEST_METHOD'] = 'GET';
if (!isset($_SERVER['argv'][1])) {
$_SERVER['argc']++;
$_SERVER['argv'][1] = '/';
}
if (substr($_SERVER['argv'][1], 0, 1) == '/') {
$_SERVER['REQUEST_URI'] = $_SERVER['argv'][1];
} else {
$req = $opts = '';
foreach ($_SERVER['argv'] as $i => $arg) {
if (!$i) {
continue;
}
if (preg_match('/^\\-(\\-)?(\\w+)(?:\\=(.*))?$/', $arg, $m)) {
foreach ($m[1] ? [$m[2]] : str_split($m[2]) as $k) {
$opts .= ($opts ? '&' : '') . $k . '=';
}
if (isset($m[3])) {
$opts .= $m[3];
}
} else {
$req .= '/' . $arg;
}
}
$_SERVER['REQUEST_URI'] = ($req ?: '/') . '?' . urlencode($opts);
parse_str($opts, $GLOBALS['_GET']);
}
}
$headers = [];
if (!$cli) {
if (function_exists('getallheaders')) {
foreach (getallheaders() as $key => $val) {
$tmp = strtoupper(strtr($key, '-', '_'));
// TODO: use ucwords delimiters for php 5.4.32+ & 5.5.16+
$key = strtr(ucwords(strtolower(strtr($key, '-', ' '))), ' ', '-');
$headers[$key] = $val;
if (isset($_SERVER['HTTP_' . $tmp])) {
$headers[$key] =& $_SERVER['HTTP_' . $tmp];
}
}
} else {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$headers['Content-Length'] =& $_SERVER['CONTENT_LENGTH'];
}
if (isset($_SERVER['CONTENT_TYPE'])) {
$headers['Content-Type'] =& $_SERVER['CONTENT_TYPE'];
}
foreach (array_keys($_SERVER) as $key) {
if (substr($key, 0, 5) == 'HTTP_') {
$headers[strtr(ucwords(strtolower(strtr(substr($key, 5), '_', ' '))), ' ', '-')] =& $_SERVER[$key];
}
}
}
}
if (isset($headers['X-HTTP-Method-Override'])) {
$_SERVER['REQUEST_METHOD'] = $headers['X-HTTP-Method-Override'];
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['_method'])) {
$_SERVER['REQUEST_METHOD'] = $_POST['_method'];
}
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($headers['X-Forwarded-Proto']) && $headers['X-Forwarded-Proto'] == 'https' ? 'https' : 'http';
// Create hive early on to expose header methods
$this->hive = ['HEADERS' => &$headers];
if (function_exists('apache_setenv')) {
// Work around Apache pre-2.4 VirtualDocumentRoot bug
$_SERVER['DOCUMENT_ROOT'] = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['SCRIPT_FILENAME']);
apache_setenv("DOCUMENT_ROOT", $_SERVER['DOCUMENT_ROOT']);
}
$_SERVER['DOCUMENT_ROOT'] = realpath($_SERVER['DOCUMENT_ROOT']);
$base = '';
if (!$cli) {
$base = rtrim($this->fixslashes(dirname($_SERVER['SCRIPT_NAME'])), '/');
}
$uri = parse_url($_SERVER['REQUEST_URI']);
$path = preg_replace('/^' . preg_quote($base, '/') . '/', '', $uri['path']);
session_cache_limiter('');
call_user_func_array('session_set_cookie_params', $jar = ['expire' => 0, 'path' => $base ?: '/', 'domain' => is_int(strpos($_SERVER['SERVER_NAME'], '.')) && !filter_var($_SERVER['SERVER_NAME'], FILTER_VALIDATE_IP) ? $_SERVER['SERVER_NAME'] : '', 'secure' => $scheme == 'https', 'httponly' => TRUE]);
$port = 0;
if (isset($_SERVER['SERVER_PORT'])) {
$port = $_SERVER['SERVER_PORT'];
}
// Default configuration
$this->hive += ['AGENT' => $this->agent(), 'AJAX' => $this->ajax(), 'ALIAS' => NULL, 'ALIASES' => [], 'AUTOLOAD' => './', 'BASE' => $base, 'BITMASK' => ENT_COMPAT, 'BODY' => NULL, 'CACHE' => FALSE, 'CASELESS' => TRUE, 'CLI' => $cli, 'CORS' => ['headers' => '', 'origin' => FALSE, 'credentials' => FALSE, 'expose' => FALSE, 'ttl' => 0], 'DEBUG' => 0, 'DIACRITICS' => [], 'DNSBL' => '', 'EMOJI' => [], 'ENCODING' => $charset, 'ERROR' => NULL, 'ESCAPE' => TRUE, 'EXCEPTION' => NULL, 'EXEMPT' => NULL, 'FALLBACK' => $this->fallback, 'FORMATS' => [], 'FRAGMENT' => isset($uri['fragment']) ? $uri['fragment'] : '', 'HALT' => TRUE, 'HIGHLIGHT' => FALSE, 'HOST' => $_SERVER['SERVER_NAME'], 'IP' => $this->ip(), 'JAR' => $jar, 'LANGUAGE' => isset($headers['Accept-Language']) ? $this->language($headers['Accept-Language']) : $this->fallback, 'LOCALES' => './', 'LOGS' => './', 'ONERROR' => NULL, 'ONREROUTE' => NULL, 'PACKAGE' => self::PACKAGE, 'PARAMS' => [], 'PATH' => $path, 'PATTERN' => NULL, 'PLUGINS' => $this->fixslashes(__DIR__) . '/', 'PORT' => $port, 'PREFIX' => NULL, 'PREMAP' => '', 'QUERY' => isset($uri['query']) ? $uri['query'] : '', 'QUIET' => FALSE, 'RAW' => FALSE, 'REALM' => $scheme . '://' . $_SERVER['SERVER_NAME'] . ($port && $port != 80 && $port != 443 ? ':' . $port : '') . $_SERVER['REQUEST_URI'], 'RESPONSE' => '', 'ROOT' => $_SERVER['DOCUMENT_ROOT'], 'ROUTES' => [], 'SCHEME' => $scheme, 'SEED' => $this->hash($_SERVER['SERVER_NAME'] . $base), 'SERIALIZER' => extension_loaded($ext = 'igbinary') ? $ext : 'php', 'TEMP' => 'tmp/', 'TIME' => &$_SERVER['REQUEST_TIME_FLOAT'], 'TZ' => @date_default_timezone_get(), 'UI' => './', 'UNLOAD' => NULL, 'UPLOADS' => './', 'URI' => &$_SERVER['REQUEST_URI'], 'VERB' => &$_SERVER['REQUEST_METHOD'], 'VERSION' => self::VERSION, 'XFRAME' => 'SAMEORIGIN'];
if (PHP_SAPI == 'cli-server' && preg_match('/^' . preg_quote($base, '/') . '$/', $this->hive['URI'])) {
$this->reroute('/');
}
if (ini_get('auto_globals_jit')) {
// Override setting
$GLOBALS += ['_ENV' => $_ENV, '_REQUEST' => $_REQUEST];
}
// Sync PHP globals with corresponding hive keys
$this->init = $this->hive;
foreach (explode('|', self::GLOBALS) as $global) {
$sync = $this->sync($global);
$this->init += [$global => preg_match('/SERVER|ENV/', $global) ? $sync : []];
}
if ($check && ($error = error_get_last())) {
// Error detected
$this->error(500, sprintf(self::E_Fatal, $error['message']), [$error]);
}
date_default_timezone_set($this->hive['TZ']);
// Register framework autoloader
spl_autoload_register([$this, 'autoload']);
// Register shutdown handler
register_shutdown_function([$this, 'unload'], getcwd());
}