_arrayMergeRecursive($config, $localConfig); } if (!defined('PATH_SEPARATOR')) { $config[$section]['PATH_SEPARATOR'] = (getenv('COMSPEC')) ? ';' : ':'; } if (null === $config['define']['DEBUG']) { $config['define']['DEBUG'] = ( self::isReservedIp($_SERVER['REMOTE_ADDR']) || in_array($_SERVER['REMOTE_ADDR'], $config['debug']['ips']) ) && isset($_COOKIE[$config['debug']['cookie']]); } $this->_initBaseurlWebpath($config[$section]); $config[$section]['BASE_PATH'] = realpath($config[$section]['WWW_PATH'] . '/' . $config[$section]['BASE_PATH']); if (!isset($config[$section]['SESSION_SAVE_PATH'])) { $config[$section]['SESSION_SAVE_PATH'] = $config[$section]['BASE_PATH'] . '/tmp/session'; } if (!in_array($config[$section]['APPLICATION_ENV'], $this->_appEnvs)) { die( 'Configuration Error: "' . $config[$section]['APPLICATION_ENV'] . '" is wrong Application Environment. Use one value of: ' . implode(', ', $this->_appEnvs) . '.' ); } define('APPLICATION_ENV', $config[$section]['APPLICATION_ENV']); define('SITE_NAME', $config[$section]['SITE_NAME']); define('BASE_PATH', $config[$section]['BASE_PATH']); define('SESSION_SAVE_PATH', $config[$section]['SESSION_SAVE_PATH']); define('BASE_URL', $config[$section]['BASE_URL']); define('DEBUG', $config[$section]['DEBUG']); define('WWW_PATH', $config[$section]['WWW_PATH']); define('WEB_PATH', $config[$section]['WEB_PATH']); define('BASE_URL_HTTP', $config[$section]['BASE_URL_HTTP']); define('BASE_URL_HTTPS', $config[$section]['BASE_URL_HTTPS']); define('COMPRESS_HTML', $config[$section]['COMPRESS_HTML']); define('OPTIMIZE_RESOURCES', $config[$section]['OPTIMIZE_RESOURCES']); define('USE_PACKED_RESOURCES', $config[$section]['USE_PACKED_RESOURCES']); foreach($config[$section] as $var => $value) { $var = strtoupper($var); if (!defined($var)) { define($var, $value); } } } public static function isReservedIp($ip) { $long = ip2long($ip); // check for 10.0.0.0 - 10.255.255.255 if (10 == $long >> 24) { return true; } // TODO check for 172.16.0.0 - 172.31.255.255 // TODO check for 192.168.0.0 - 192.168.255.255 return false; } protected function _initBaseurlWebpath(&$config) { $host = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']; $config['WWW_PATH'] = realpath('.'); $config['BASE_URL'] = $host . str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); $config['BASE_URL'] = substr($config['BASE_URL'], 0, -1); while (!is_file($config['WWW_PATH'] . '/_lib/_sys/Frwd_ConfigLite.php')) { $config['WWW_PATH'] = dirname($config['WWW_PATH']); $config['BASE_URL'] = dirname($config['BASE_URL']); if ('/' == $config['WWW_PATH']) { die('INCORECT SCRIPT LOCATION'); } } $config['BASE_URL_HTTP'] = str_replace('https://', 'http://', $config['BASE_URL']); $config['BASE_URL_HTTPS'] = str_replace('http://', 'https://', $config['BASE_URL']); $config['WEB_PATH'] = str_replace($host, '', $config['BASE_URL']); return true; } protected function _arrayMergeRecursive($array1, $array2) { if (is_array($array1) && is_array($array2)) { foreach ($array2 as $key => $value) { if (isset($array1[$key])) { $array1[$key] = $this->_arrayMergeRecursive($array1[$key], $value); } else { $array1[$key] = $value; } } } else { $array1 = $array2; } return $array1; } }