Exemple #1
0
 /**
  * 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'];
 }
Exemple #3
0
 /**
  * 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'];
 }
Exemple #4
0
 /**
  * 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);
     }
 }
Exemple #5
0
 /**
  * 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']);
 }
 public function testSameStringInPath()
 {
     $this->assertSame('[PROJECT]\\var\\www\\facula\\Some\\Sub\\Path', Target::replacePathPrefix('\\var\\www\\facula', '[PROJECT]', '\\var\\www\\facula\\var\\www\\facula\\Some\\Sub\\Path'));
 }
Exemple #7
0
 /**
  * Display a error message to user
  *
  * @param array $backTraces Back traces information
  * @param array $banner Banner setting
  *
  * @return string The rendered result according back traces info and banner setting
  */
 protected static function renderErrorDetailBanners(array $backTraces, array $banner)
 {
     if (empty($backTraces)) {
         return '';
     }
     $tracesLoop = 0;
     $detail = $banner['Start'];
     foreach ($backTraces as $key => $val) {
         $tracesLoop++;
         $tempFilePath = PathParser::replacePathPrefixes(array(Framework::ROOT, Framework::PATH), array('[FACULA]', '[PROJECT]'), $val['file']);
         $assigns = array('%Error:Banner:No%' => $tracesLoop, '%Error:Banner:Caller%' => $val['caller'], '%Error:Banner:File%' => $tempFilePath, '%Error:Banner:Line%' => $val['line'], '%Error:Banner:Plate:Author%' => $val['nameplate']['author'], '%Error:Banner:Plate:Reviser%' => $val['nameplate']['reviser'], '%Error:Banner:Plate:Contact%' => $val['nameplate']['contact'], '%Error:Banner:Plate:Updated%' => $val['nameplate']['updated'], '%Error:Banner:Plate:Version%' => $val['nameplate']['version'], '%Error:Banner:Caller:Html%' => htmlspecialchars($val['caller'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:File:Html%' => htmlspecialchars($tempFilePath, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:Line:Html%' => htmlspecialchars($val['line'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:Plate:Author:Html%' => htmlspecialchars($val['nameplate']['author'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:Plate:Reviser:Html%' => htmlspecialchars($val['nameplate']['reviser'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:Plate:Contact:Html%' => htmlspecialchars($val['nameplate']['contact'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:Plate:Updated:Html%' => htmlspecialchars($val['nameplate']['updated'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '%Error:Banner:Plate:Version:Html%' => htmlspecialchars($val['nameplate']['version'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
         $detail .= str_replace(array_keys($assigns), array_values($assigns), $banner['Code']);
     }
     $detail .= $banner['End'];
     return $detail;
 }
 /**
  * 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']);
 }
Exemple #9
0
 /**
  * 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;
             }
         }
     }
 }