示例#1
0
 /**
  * Create a new CouchDbSvc
  *
  * @param array $settings
  *
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 public function __construct($settings = [])
 {
     parent::__construct($settings);
     $config = ArrayUtils::clean(ArrayUtils::get($settings, 'config'));
     Session::replaceLookups($config, true);
     $dsn = strval(ArrayUtils::get($config, 'dsn'));
     if (empty($dsn)) {
         $dsn = 'http://localhost:5984';
     }
     $options = [];
     if (isset($config['options'])) {
         $options = $config['options'];
     }
     $db = isset($options['db']) ? $options['db'] : null;
     if (!isset($db)) {
         //  Attempt to find db in connection string
         $temp = trim(strstr($dsn, '//'), '/');
         $db = strstr($temp, '/');
         $db = trim($db, '/');
     }
     if (empty($db)) {
         $db = 'default';
     }
     try {
         $this->dbConn = @new \couchClient($dsn, $db, $options);
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("CouchDb Service Exception:\n{$ex->getMessage()}");
     }
 }
示例#2
0
 /**
  * Create a new DynamoDb
  *
  * @param array $settings
  *
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 public function __construct($settings = [])
 {
     parent::__construct($settings);
     $config = ArrayUtils::clean(ArrayUtils::get($settings, 'config'));
     //  Replace any private lookups
     Session::replaceLookups($config, true);
     // statically assign our supported version
     $config['version'] = '2012-08-10';
     if (isset($config['key'])) {
         $config['credentials']['key'] = $config['key'];
     }
     if (isset($config['secret'])) {
         $config['credentials']['secret'] = $config['secret'];
     }
     // set up a default table schema
     $parameters = ArrayUtils::clean(ArrayUtils::get($config, 'parameters'));
     Session::replaceLookups($parameters);
     if (null !== ($table = ArrayUtils::get($parameters, 'default_create_table'))) {
         $this->defaultCreateTable = $table;
     }
     try {
         $this->dbConn = new DynamoDbClient($config);
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("AWS DynamoDb Service Exception:\n{$ex->getMessage()}", $ex->getCode());
     }
 }
示例#3
0
 /**
  * Create a new AzureTablesSvc
  *
  * @param array $settings
  *
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 public function __construct($settings = array())
 {
     parent::__construct($settings);
     $config = ArrayUtils::clean(ArrayUtils::get($settings, 'config'));
     Session::replaceLookups($config, true);
     $dsn = strval(ArrayUtils::get($config, 'connection_string'));
     if (empty($dsn)) {
         $name = ArrayUtils::get($config, 'account_name', ArrayUtils::get($config, 'AccountName'));
         if (empty($name)) {
             throw new \InvalidArgumentException('WindowsAzure account name can not be empty.');
         }
         $key = ArrayUtils::get($config, 'account_key', ArrayUtils::get($config, 'AccountKey'));
         if (empty($key)) {
             throw new \InvalidArgumentException('WindowsAzure account key can not be empty.');
         }
         $protocol = ArrayUtils::get($config, 'protocol', 'https');
         $dsn = "DefaultEndpointsProtocol={$protocol};AccountName={$name};AccountKey={$key}";
     }
     // set up a default partition key
     $partitionKey = ArrayUtils::get($config, static::PARTITION_KEY);
     if (!empty($partitionKey)) {
         $this->defaultPartitionKey = $partitionKey;
     }
     try {
         $this->dbConn = ServicesBuilder::getInstance()->createTableService($dsn);
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("Windows Azure Table Service Exception:\n{$ex->getMessage()}");
     }
 }
示例#4
0
 /**
  * Create a new MongoDbSvc
  *
  * @param array $settings
  *
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 public function __construct($settings = [])
 {
     parent::__construct($settings);
     static::checkExtensions(['mongo']);
     $config = ArrayUtils::clean(ArrayUtils::get($settings, 'config'));
     Session::replaceLookups($config, true);
     $dsn = strval(ArrayUtils::get($config, 'dsn'));
     if (!empty($dsn)) {
         if (0 != substr_compare($dsn, static::DSN_PREFIX, 0, static::DSN_PREFIX_LENGTH, true)) {
             $dsn = static::DSN_PREFIX . $dsn;
         }
     }
     $options = ArrayUtils::get($config, 'options', []);
     if (empty($options)) {
         $options = [];
     }
     $user = ArrayUtils::get($config, 'username');
     $password = ArrayUtils::get($config, 'password');
     // support old configuration options of user, pwd, and db in credentials directly
     if (!isset($options['username']) && isset($user)) {
         $options['username'] = $user;
     }
     if (!isset($options['password']) && isset($password)) {
         $options['password'] = $password;
     }
     if (!isset($options['db']) && null !== ($db = ArrayUtils::get($config, 'db', null, true))) {
         $options['db'] = $db;
     }
     if (!isset($db) && null === ($db = ArrayUtils::get($options, 'db', null, true))) {
         //  Attempt to find db in connection string
         $db = strstr(substr($dsn, static::DSN_PREFIX_LENGTH), '/');
         if (false !== ($pos = strpos($db, '?'))) {
             $db = substr($db, 0, $pos);
         }
         $db = trim($db, '/');
     }
     if (empty($db)) {
         throw new InternalServerErrorException("No MongoDb database selected in configuration.");
     }
     $driverOptions = ArrayUtils::clean(ArrayUtils::get($config, 'driver_options'));
     if (null !== ($context = ArrayUtils::get($driverOptions, 'context'))) {
         //  Automatically creates a stream from context
         $driverOptions['context'] = stream_context_create($context);
     }
     try {
         $client = @new \MongoClient($dsn, $options, $driverOptions);
         $this->dbConn = $client->selectDB($db);
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("Unexpected MongoDb Service Exception:\n{$ex->getMessage()}");
     }
 }
 /**
  * Create a new SalesforceDbSvc
  *
  * @param array $settings
  *
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 public function __construct($settings = array())
 {
     parent::__construct($settings);
     $config = ArrayUtils::clean(ArrayUtils::get($settings, 'config'));
     Session::replaceLookups($config, true);
     $this->username = ArrayUtils::get($config, 'username');
     $this->password = ArrayUtils::get($config, 'password');
     $this->securityToken = ArrayUtils::get($config, 'security_token');
     if (empty($this->securityToken)) {
         $this->securityToken = '';
         // gets appended to password
     }
     if (empty($this->username) || empty($this->password)) {
         throw new \InvalidArgumentException('A Salesforce username and password are required for this service.');
     }
     $version = ArrayUtils::get($config, 'version');
     if (!empty($version)) {
         $this->version = $version;
     }
     $this->sessionCache = [];
     //
     //        $this->fieldCache = array();
 }