/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param Framework $facula The framework itself */ public function __construct(array &$cfg, array $common, Framework $facula) { $cp = new ConfigParser($cfg, static::$defaultSetting); if ($cp->isEmpty('CacheRoot') || !is_dir($cp->get('CacheRoot'))) { new Error('CACHEPATH_NOTFOUND', array($cp->isEmpty('CacheRoot')), 'ERROR'); return; } $this->configs = array('Root' => PathParser::get($cp->get('CacheRoot')), 'Version' => $common['Version']); }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param Framework $facula The framework itself */ public function __construct(array &$cfg, array $common, Framework $facula) { $cp = new ConfigParser($cfg, static::$defaultSetting); // General settings $this->configs = array('Cache' => $cp->get('CacheTemplate'), 'Compress' => $cp->get('CompressOutput'), 'Renew' => $cp->get('ForceRenew'), 'CacheTTL' => $cp->get('CacheMaxLifeTime'), 'Charset' => strtoupper($cp->get('Charset', isset($common['Charset']) ? $common['Charset'] : null)), 'AspTags' => Ini::has('asp_tags') ? Ini::getBool('asp_tags') : false, 'CacheBegin' => $common['BootTime'], 'BootTime' => $common['BootTime'], 'BootVersion' => $common['BootVersion']); // Use custom render if (!$cp->isEmpty('Render')) { if (!class_exists($cp->get('Render'))) { new Error('RENDER_CLASS_NOTFOUND', array($cp->get('Render')), 'ERROR'); return; } if (!class_implements($cp->get('Render'), static::$operatorsImpl['Render'])) { new Error('RENDER_INTERFACE_INVALID', array($cp->get('Render'), static::$operatorsImpl['Render']), 'ERROR'); return; } $this->configs['Render'] = $cp->get('Render'); } // Use custom compiler if (!$cp->isEmpty('Compiler')) { if (!class_exists($cp->get('Compiler'))) { new Error('COMPILER_CLASS_NOTFOUND', array($cp->get('Compiler')), 'ERROR'); return; } if (!class_implements($cp->get('Compiler'), static::$operatorsImpl['Compiler'])) { new Error('COMPILER_INTERFACE_INVALID', array($cp->get('Compiler'), static::$operatorsImpl['Compiler']), 'ERROR'); return; } $this->configs['Compiler'] = $cp->get('Compiler'); } // TemplatePool if (!$cp->isEmpty('TemplatePool') && is_dir($cp->get('TemplatePool'))) { $this->configs['TplPool'] = PathParser::get($cp->get('TemplatePool')); } else { new Error('PATH_TEMPLATEPOOL_NOTFOUND', array(), 'ERROR'); return; } // CompiledTemplate if (!$cp->isEmpty('CompiledTemplate') && is_dir($cp->get('CompiledTemplate'))) { $this->configs['Compiled'] = PathParser::get($cp->get('CompiledTemplate')); } else { new Error('PATH_COMPILEDTEMPLATE_NOTFOUND', array(), 'ERROR'); return; } // Check if cache path has set if ($this->configs['Cache']) { if (!$cp->isEmpty('CachePath') && is_dir($cp->get('CachePath'))) { $this->configs['Cached'] = PathParser::get($cp->get('CachePath')); } else { new Error('PATH_CACHEDTEMPLATE_NOTFOUND', array(), 'ERROR'); return; } } $this->pool['SupportedLanguages'] = array(); if ($this->loadFileMap() && isset(static::$fileMap['Lang'])) { $this->pool['SupportedLanguages'] = array_keys(static::$fileMap['Lang']); } $this->assigned['RootURL'] = $facula->request->getClientInfo('rootURL'); $this->assigned['HostURIFormatted'] = $facula->request->getClientInfo('hostURIFormatted'); $this->assigned['AbsRootURL'] = $facula->request->getClientInfo('absRootURL'); $this->assigned['AbsRootFormatted'] = $facula->request->getClientInfo('absRootFormatted'); $this->assigned['_BOOT_VERSION'] = $this->configs['BootVersion']; $this->assigned['_BOOT_TIME'] = $this->configs['BootTime']; }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param Framework $facula The framework itself */ public function __construct(array &$cfg, array $common, Framework $facula) { if (!class_exists('PDO')) { new Error('PDO_UNSUPPORTED', array(), 'ERROR'); return; } $cp = new ConfigParser($cfg, static::$defaultSetting); $this->configs = array('DefaultTimeout' => $cp->get('DefaultTimeout'), 'WaitTimeout' => $cp->get('WaitTimeout'), 'SelectMethod' => $cp->get('SelectMethod'), 'PriorMethod' => $cp->get('PriorMethod')); $supportedDrivers = PHPPDO::getAvailableDrivers(); if ($cp->isEmpty('DatabaseGroup')) { new Error('DBGROUP_DECLARATION_NEEDED', array(), 'ERROR'); return; } foreach ($cp->get('DatabaseGroup') as $index => $database) { $dbItem = new ConfigParser($database, static::$defaultSettingItem); if ($dbItem->isEmpty('Driver')) { new Error('DRIVER_DECLARATION_NEEDED', array($index, implode(', ', $supportedDrivers)), 'ERROR'); return; } if (!in_array($dbItem->get('Driver'), $supportedDrivers)) { new Error('DRIVER_UNSUPPORTED', array($dbItem->get('Driver'), $index, implode(', ', $supportedDrivers)), 'ERROR'); return; } // Parse and save config to instance $this->pool['DBs'][$index] = array('ID' => $index, 'Driver' => $dbItem->get('Driver'), 'Connection' => $dbItem->get('Connection'), 'Prefix' => $dbItem->get('Prefix'), 'Username' => $dbItem->get('Username'), 'Password' => $dbItem->get('Password'), 'Timeout' => $dbItem->get('Timeout') ? $dbItem->get('Timeout') : $this->configs['DefaultTimeout'], 'Wait' => $dbItem->get('Wait') ? $dbItem->get('Wait') : $this->configs['WaitTimeout'], 'LstConnected' => 0, 'Persistent' => $dbItem->get('Persistent'), 'Options' => $dbItem->get('Options')); // If needed, add current item to Table mapping for search filter. switch ($this->configs['SelectMethod']) { case 'Table': case 'Table+Operation': if ($dbItem->has('Tables')) { foreach ($dbItem->get('Tables') as $table) { $this->pool['TTDBs'][$table][$index] =& $this->pool['DBs'][$index]; // Add Tables to Database item $this->pool['DBs'][$index]['Tables'][] = $table; } } else { new Error('TABLE_DECLARATION_NEEDED', array($index), 'ERROR'); return; } break; default: break; } // If needed, add current item to Permission mapping for search filter. switch ($this->configs['SelectMethod']) { case 'Table': case 'Table+Operation': if ($dbItem->has('Operates')) { foreach ($dbItem->get('Operates') as $key => $operation) { $this->pool['OTDBs'][$operation][$index] =& $this->pool['DBs'][$index]; // Add Operates to Database item $this->pool['DBs'][$index]['Operations'][] = $operation; } } else { new Error('OPERATION_DECLARATION_NEEDED', array($index), 'ERROR'); return; } break; default: break; } // Mapping current database item to connection status store $this->map['DBConn'][$index] = array('Connection' => null, 'Database' => &$this->pool['DBs'][$index]); // Mapping current database item to Prioritize store for later use // DBP for sort the database item so we can shuffle it without disturb database index $this->map['DBP'][$index] =& $this->pool['DBs'][$index]; } }
/** * SMTP Constructor * * @param array $config Configuration for initialize the class * * @throws Exception\ServerFromAddressInvalid * @throws Exception\ServerReplyToAddressInvalid * @throws Exception\ServerReturnToAddressInvalid * @throws Exception\ServerErrorToAddressInvalid * @throws Exception\NoServerSpecified */ public function __construct(array &$config) { $typeVerified = array(); $cp = new ConfigParser($config, static::$defaultConfig); $version = Framework::getVersion(); $senderIP = IP::joinIP(Framework::core('request')->getClientInfo('ipArray'), true); $this->config['Handler'] = $version['App'] . ' ' . $version['Ver']; if ($cp->isEmpty('Servers')) { throw new Exception\NoServerSpecified(); } $this->config['Temp'] = PathParser::get($cp->getValid('TempFilesDir', function ($val) { return is_dir($val); }, sys_get_temp_dir())); $servers = $cp->get('Servers'); if ($cp->has('SelectMethod')) { switch ($cp->get('SelectMethod')) { case 'SelectMethod': shuffle($servers); break; } } foreach ($servers as $key => $val) { $serverCP = new ConfigParser($val, static::$defaultServerConfig); $mailUserName = $serverCP->get('Username'); $mailDefaultFrom = strpos($mailUserName, '@') !== false ? $mailUserName : $mailUserName . '@' . $serverCP->get('Host'); $emailFrom = $serverCP->getValid('From', function ($val) { if (empty($val)) { return false; } if (!Validator::check($val, 'email')) { throw new Exception\ServerFromAddressInvalid($val); } return true; }, $mailDefaultFrom); $this->config['Servers'][$key] = array('Host' => $serverCP->get('Host'), 'Port' => $serverCP->get('Port'), 'Type' => $serverCP->getValid('Type', function ($val) use(&$typeVerified) { if (empty($val)) { return false; } if (isset($typeVerified[$val])) { return true; } if (!isset(static::$operators[$val])) { throw new Exception\UnknownServerType($val); } $optClass = static::$operators[$val]; if (!class_exists($optClass)) { throw new Exception\OperatorClassNotFound($optClass, $val); } $parents = class_parents($optClass); if (!isset($parents)) { throw new Exception\OperatorExtendsInvalid($optClass); } $typeVerified[$val] = true; return true; }, 'General'), 'Timeout' => $serverCP->get('Timeout'), 'Retry' => $serverCP->get('Retry'), 'Username' => $mailUserName, 'Password' => $serverCP->get('Password'), 'Handler' => $this->config['Handler'], 'ScreenName' => $serverCP->get('ScreenName', $serverCP->get('Username')), 'From' => $emailFrom, 'ReplyTo' => $serverCP->getValid('ReplyTo', function ($val) { if (empty($val)) { return false; } if (!Validator::check($val, 'email')) { throw new Exception\ServerReplyToAddressInvalid($val); } return true; }, $emailFrom), 'ReturnTo' => $serverCP->getValid('ReturnTo', function ($val) { if (empty($val)) { return false; } if (!Validator::check($val, 'email')) { throw new Exception\ServerReturnToAddressInvalid($val); } return true; }, $emailFrom), 'ErrorTo' => $serverCP->getValid('ReturnTo', function ($val) { if (empty($val)) { return false; } if (!Validator::check($val, 'email')) { throw new Exception\ServerErrorToAddressInvalid($val); } return true; }, $emailFrom), 'SignCert' => PathParser::get($serverCP->getValid('SignatureCert', function ($val) { if (empty($val)) { return false; } if (!is_readable($val)) { throw new Exception\ServerSignCertNotReadable($val); } return true; }, '')), 'SignKey' => PathParser::get($serverCP->getValid('SignatureKey', function ($val) { if (empty($val)) { return false; } if (!is_readable($val)) { throw new Exception\ServerSignKeyNotReadable($val); } return true; }, '')), 'SignPass' => $serverCP->get('SignaturePass'), 'SignChain' => PathParser::get($serverCP->getValid('SignatureChain', function ($val) { if (empty($val)) { return false; } if (!is_readable($val)) { throw new Exception\ServerSignChainNotReadable($val); } return true; }, '')), 'SenderIP' => $senderIP); } }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param Framework $facula The framework itself */ public function __construct(array &$cfg, array $common, Framework $facula) { $cp = new ConfigParser($cfg, static::$defaultSetting); $this->configs = array('OCRoot' => !$cp->isEmpty('ObjectCacheRoot') && is_dir($cp->get('ObjectCacheRoot')) ? PathParser::get($cp->get('ObjectCacheRoot')) : '', 'OCExpire' => $cp->get('ObjectCacheExpire'), 'CacheVer' => $common['BootVersion']); }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param Framework $facula The framework itself */ public function __construct(array &$cfg, array $common, Framework $facula) { global $_SERVER; $cp = new ConfigParser($cfg, static::$defaultSetting); if (function_exists('get_magic_quotes_gpc')) { $this->configs['AutoMagicQuotes'] = get_magic_quotes_gpc(); } if ($cp->get('DenyExternalSubmit')) { $this->configs['NoExtSubmit'] = true; } else { $this->configs['NoExtSubmit'] = false; } if (!$cp->isEmpty('MaxDataSize')) { // Give memory_limit * 0.6 because we needs memory to run other stuffs, so memory // cannot be 100%ly use for handle request data; $this->configs['MaxDataSize'] = min($cp->get('MaxDataSize'), Ini::getBytes('post_max_size'), Ini::getBytes('memory_limit') * 0.6); } else { $this->configs['MaxDataSize'] = min(Ini::getBytes('post_max_size'), Ini::getBytes('memory_limit') * 0.6); } // CDN or approved proxy servers if ($cp->isEmpty('TrustedProxies') || !defined('FILTER_FLAG_IPV4')) { $this->configs['TrustedProxies'] = array(); } else { $proxyIPTemp = array(); if (defined('AF_INET6') && defined('FILTER_FLAG_IPV6')) { $this->configs['TPVerifyFlags'] = FILTER_FLAG_IPV4 + FILTER_FLAG_IPV6; } else { $this->configs['TPVerifyFlags'] = FILTER_FLAG_IPV4; } foreach ($cp->get('TrustedProxies') as $proxy) { $proxyIPRange = explode('-', $proxy, 2); foreach ($proxyIPRange as $proxyIP) { if (!filter_var($proxyIP, FILTER_VALIDATE_IP, $this->configs['TPVerifyFlags'])) { new Error('PROXYADDR_INVALID', array($proxyIP), 'ERROR'); return; break 2; } } if (isset($proxyIPRange[1])) { $proxyIPTemp[0] = inet_pton($proxyIPRange[0]); $proxyIPTemp[1] = inet_pton($proxyIPRange[1]); if ($proxyIPTemp[0] < $proxyIPTemp[1]) { $this->configs['TrustedProxies'][$proxyIPTemp[0]] = $proxyIPTemp[1]; } elseif ($proxyIPTemp[0] > $proxyIPTemp[1]) { $this->configs['TrustedProxies'][$proxyIPTemp[1]] = $proxyIPTemp[0]; } else { $this->configs['TrustedProxies'][$proxyIPTemp[0]] = false; } continue; } $this->configs['TrustedProxies'][inet_pton($proxyIPRange[0])] = false; } // Proxy header, like `X-Forward-For` etc if ($cp->isEmpty('TrustedProxyIPHeaders')) { new Error('PROXYXFF_HEADER_MUST_BE_DEFINED', array(implode(', ', array_keys(static::$allowedXFFHeaders))), 'ERROR'); return; } $currentXFFPriories = count($cp->get('TrustedProxyIPHeaders')); foreach ($cp->get('TrustedProxyIPHeaders') as $xffHeader) { if (!isset(static::$allowedXFFHeaders[$xffHeader])) { new Error('PROXYXFF_HEADER_INVALID', array($xffHeader, implode(', ', array_keys(static::$allowedXFFHeaders))), 'ERROR'); return; } $this->configs['TrustedXFFHeader'][static::$allowedXFFHeaders[$xffHeader]] = $currentXFFPriories--; } } // We can handle up to 512 elements in _GET + _POST + _COOKIE + SERVER array $this->configs['MaxRequestBlocks'] = $cp->get('MaxRequestBlocks'); // How long of the data we can handle. $this->configs['MaxHeaderSize'] = $cp->get('MaxHeaderSize'); $this->configs['CookiePrefix'] = !empty($common['CookiePrefix']) ? $common['CookiePrefix'] : ''; // Get environment variables // Get current absolute root, only work for HTTP request if (!empty($_SERVER['REQUEST_METHOD'])) { // Get current path if (!empty($common['SitePath'])) { $this->requestInfo['rootURL'] = $common['SitePath']; } elseif (!empty($_SERVER['SCRIPT_NAME'])) { $this->requestInfo['rootURL'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); } else { new Error('UNKNOWN_SITE_PATH', array(), 'ERROR'); return; } // Get current host & port if (!empty($common['SiteHost'])) { $httpHostSplited = explode(':', $common['SiteHost'], 2); $hostName = !empty($httpHostSplited[0]) ? trim($httpHostSplited[0]) : 'localhost'; $hostPort = !empty($httpHostSplited[1]) ? trim($httpHostSplited[1]) : '80'; if (empty($common['SiteScheme'])) { $hostScheme = $this->isHTTPS() ? 'https' : 'http'; } else { $hostScheme = strtolower(trim($common['SiteScheme'])); } } elseif (!empty($_SERVER['SERVER_NAME']) && !empty($_SERVER['SERVER_PORT'])) { $hostName = $_SERVER['SERVER_NAME']; $hostPort = $_SERVER['SERVER_PORT']; $hostScheme = $this->isHTTPS() ? 'https' : 'http'; } elseif (!empty($_SERVER['HTTP_HOST'])) { $httpHostSplited = explode(':', $_SERVER['HTTP_HOST'], 2); $hostName = !empty($httpHostSplited[0]) ? trim($httpHostSplited[0]) : 'localhost'; $hostPort = !empty($httpHostSplited[1]) ? trim($httpHostSplited[1]) : '80'; $hostScheme = $this->isHTTPS() ? 'https' : 'http'; } else { new Error('UNKNOWN_SITE_HOST', array(), 'ERROR'); return; } $this->requestInfo['expectedHost'] = $hostName; $this->requestInfo['expectedPort'] = (int) $hostPort; $this->requestInfo['hostURIFormatted'] = '%s//' . $this->requestInfo['expectedHost'] . '%s'; $this->requestInfo['absRootFormatted'] = $this->requestInfo['hostURIFormatted'] . $this->requestInfo['rootURL']; $this->requestInfo['absRootURL'] = sprintf($this->requestInfo['absRootFormatted'], $hostScheme . ':', $hostScheme === 'https' ? $this->requestInfo['expectedPort'] === 443 ? '' : ':' . $this->requestInfo['expectedPort'] : ($this->requestInfo['expectedPort'] === 80 ? '' : ':' . $this->requestInfo['expectedPort'])); } }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param Framework $facula The framework itself */ public function __construct(array &$cfg, array $common, Framework $facula) { $cp = new ConfigParser($cfg, static::$defaultSetting); $this->configs = array('Strict' => $cp->get('Strict'), 'LogRoot' => !$cp->isEmpty('LogRoot') && is_dir($cp->get('LogRoot')) ? PathParser::get($cp->get('LogRoot')) : '', 'Debug' => $cp->get('Debug'), 'ServerName' => $common['PHP']['ServerName'], 'SAPI' => strtolower($common['PHP']['SAPI']), 'BootTime' => $common['BootTime'], 'AppName' => $common['AppName'], 'AppVersion' => $common['AppVersion']); }