/** * 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 \Facula\Framework $facula The framework itself * * @return void */ public function __construct(&$cfg, $common) { if (isset($cfg['CacheRoot'][0]) && is_dir($cfg['CacheRoot'])) { $this->configs['Root'] = PathParser::get($cfg['CacheRoot']); } else { new Error('CACHEPATH_NOTFOUND', array(), 'ERROR'); return; } $this->configs['BootVer'] = $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) { $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']; }
/** * 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) { $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']); }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param \Facula\Framework $facula The framework itself * * @return void */ public function __construct(&$cfg, $common) { $this->configs = array('Strict' => isset($cfg['Strict']) && $cfg['Strict'] ? true : false, 'LogRoot' => isset($cfg['LogRoot']) && is_dir($cfg['LogRoot']) ? PathParser::get($cfg['LogRoot']) : '', 'LogServer' => array('Addr' => isset($cfg['LogServerInterface'][0]) ? $cfg['LogServerInterface'] : '', 'Key' => isset($cfg['LogServerKey'][0]) ? $cfg['LogServerKey'] : ''), 'Debug' => !isset($cfg['Debug']) || $cfg['Debug'] ? true : false, 'ServerName' => $common['PHP']['ServerName'], 'SAPI' => $common['PHP']['SAPI'], 'BootVersion' => $common['BootVersion'], 'AppName' => $common['AppName'], 'AppVersion' => $common['AppVersion']); }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param \Facula\Framework $facula The framework itself * * @return void */ public function __construct(&$cfg, $common) { $paths = array(); $this->configs = array('OCRoot' => isset($cfg['ObjectCacheRoot']) && is_dir($cfg['ObjectCacheRoot']) ? PathParser::get($cfg['ObjectCacheRoot']) : '', 'OCExpire' => isset($cfg['ObjectCacheExpire']) && $cfg['ObjectCacheExpire'] ? (int) $cfg['ObjectCacheExpire'] : 0, 'CacheTime' => $common['BootVersion']); }
/** * Discover components, and import them into Framework * * @param array $paths Path for component scan * @param array $pickedComponents Path for component scan * * @return void */ protected static function pickComponents(array $paths, array &$pickedComponents = array()) { foreach ($paths as $path) { $scanner = new Base\Tool\File\ModuleScanner(Base\Tool\File\PathParser::get($path), static::$cfg['CompMaxSeekDepth']); foreach ($scanner->scan() as $module) { switch ($module['Prefix']) { case 'include': static::$includes[] = $module['Path']; $pickedComponents['Includes'][] = $module['Path']; break; case 'initialize': static::$initializers[] = $module['Path']; $pickedComponents['Initialize'][] = $module['Path']; break; case 'routine': static::$components['Routine'][] = $module['Path']; $pickedComponents['Routine'][] = $module['Path']; break; case 'plugin': static::initPlugin($module['Path']); $pickedComponents['Plugin'][] = $module['Path']; break; case 'class': static::registerScope(ucfirst($module['Name']), $module['Path']); $pickedComponents['Class'][ucfirst($module['Name'])] = $module['Path']; break; default: static::registerScope($module['Name'], $module['Path']); $pickedComponents['Class'][$module['Name']] = $module['Path']; break; } } } }