コード例 #1
0
ファイル: PDO.php プロジェクト: raincious/facula
 /**
  * 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];
     }
 }
コード例 #2
0
ファイル: SMTP.php プロジェクト: raincious/facula
 /**
  * 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);
     }
 }