Ejemplo n.º 1
0
 /**
  * Create a new SqlDbSvc
  *
  * @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);
     $driver = isset($config['driver']) ? $config['driver'] : null;
     $this->dbConn = ConnectionFactory::createConnection($driver, $config);
     $this->dbConn->setCache($this);
     $this->dbConn->setExtraStore($this);
     $defaultSchemaOnly = ArrayUtils::getBool($config, 'default_schema_only');
     $this->dbConn->setDefaultSchemaOnly($defaultSchemaOnly);
     switch ($this->dbConn->getDBName()) {
         case SqlDbDriverTypes::MYSQL:
         case SqlDbDriverTypes::MYSQLI:
             $this->dbConn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
             break;
         case SqlDbDriverTypes::DBLIB:
             $this->dbConn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
             break;
     }
     $attributes = ArrayUtils::clean(ArrayUtils::get($settings, 'attributes'));
     if (!empty($attributes)) {
         $this->dbConn->setAttributes($attributes);
     }
 }
Ejemplo n.º 2
0
 /**
  * Connects to a Azure Blob Storage
  *
  * @param array $config Authentication configuration
  *
  * @throws InvalidArgumentException
  * @throws InternalServerErrorException
  * @throws \Exception
  */
 public function __construct($config)
 {
     $credentials = $config;
     $this->container = ArrayUtils::get($config, 'container');
     Session::replaceLookups($credentials, true);
     $connectionString = ArrayUtils::get($credentials, 'connection_string');
     if (empty($connectionString)) {
         $name = ArrayUtils::get($credentials, 'account_name', ArrayUtils::get($credentials, 'AccountName'));
         if (empty($name)) {
             throw new InvalidArgumentException('WindowsAzure account name can not be empty.');
         }
         $key = ArrayUtils::get($credentials, 'account_key', ArrayUtils::get($credentials, 'AccountKey'));
         if (empty($key)) {
             throw new InvalidArgumentException('WindowsAzure account key can not be empty.');
         }
         $protocol = ArrayUtils::get($credentials, 'protocol', 'https');
         $connectionString = "DefaultEndpointsProtocol={$protocol};AccountName={$name};AccountKey={$key}";
     }
     try {
         $this->blobConn = ServicesBuilder::getInstance()->createBlobService($connectionString);
         if (!$this->containerExists($this->container)) {
             $this->createContainer(['name' => $this->container]);
         }
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("Windows Azure Blob Service Exception:\n{$ex->getMessage()}");
     }
 }
Ejemplo n.º 3
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());
     }
 }
Ejemplo n.º 4
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()}");
     }
 }
Ejemplo n.º 5
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()}");
     }
 }
Ejemplo n.º 6
0
 /**
  * Create a new Script Service
  *
  * @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);
     if (null === ($this->content = ArrayUtils::get($config, 'content', null, true))) {
         throw new \InvalidArgumentException('Script content can not be empty.');
     }
     if (null === ($this->engineConfig = ArrayUtils::get($config, 'engine', null, true))) {
         throw new \InvalidArgumentException('Script engine configuration can not be empty.');
     }
     $this->scriptConfig = ArrayUtils::clean(ArrayUtils::get($config, 'config', [], true));
 }
Ejemplo n.º 7
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()}");
     }
 }
Ejemplo n.º 8
0
 /**
  * Create a new AwsSnsSvc
  *
  * @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 the our supported version
     $config['version'] = '2010-03-31';
     if (isset($config['key'])) {
         $config['credentials']['key'] = $config['key'];
     }
     if (isset($config['secret'])) {
         $config['credentials']['secret'] = $config['secret'];
     }
     try {
         $this->conn = new SnsClient($config);
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("AWS SNS Service Exception:\n{$ex->getMessage()}", $ex->getCode());
     }
     $this->region = ArrayUtils::get($config, 'region');
 }
Ejemplo n.º 9
0
 /**
  * @param array $config
  *
  * @throws InternalServerErrorException
  */
 public function __construct($config)
 {
     //  Replace any private lookups
     Session::replaceLookups($config, true);
     // statically assign the our supported version
     $config['version'] = '2006-03-01';
     if (isset($config['key'])) {
         $config['credentials']['key'] = $config['key'];
     }
     if (isset($config['secret'])) {
         $config['credentials']['secret'] = $config['secret'];
     }
     try {
         $this->blobConn = new S3Client($config);
     } catch (\Exception $ex) {
         throw new InternalServerErrorException("AWS DynamoDb Service Exception:\n{$ex->getMessage()}", $ex->getCode());
     }
     $this->container = ArrayUtils::get($config, 'container');
     if (!$this->containerExists($this->container)) {
         $this->createContainer(['name' => $this->container]);
     }
 }
Ejemplo n.º 10
0
 /**
  * @param      $filter
  * @param null $params
  * @param null $ss_filters
  *
  * @return array|mixed
  * @throws InternalServerErrorException
  */
 protected static function buildCriteriaArray($filter, $params = null, $ss_filters = null)
 {
     // interpret any parameter values as lookups
     $params = static::interpretRecordValues($params);
     // or as Mongo objects
     $params = static::toMongoObjects($params);
     // build filter array if necessary
     if (!is_array($filter)) {
         Session::replaceLookups($filter);
         $test = json_decode($filter, true);
         if (!is_null($test)) {
             // original filter was a json string, use it as array
             $filter = $test;
         }
     }
     $criteria = static::buildFilterArray($filter, $params);
     // add server-side filters if necessary
     $serverCriteria = static::buildSSFilterArray($ss_filters);
     if (!empty($serverCriteria)) {
         $criteria = !empty($criteria) ? ['$and' => [$criteria, $serverCriteria]] : $serverCriteria;
     }
     return $criteria;
 }
Ejemplo n.º 11
0
 /**
  * Sends out emails.
  *
  * @param array $data
  * @param null  $textView
  * @param null  $htmlView
  *
  * @return mixed
  */
 public function sendEmail($data, $textView = null, $htmlView = null)
 {
     Session::replaceLookups($textView);
     Session::replaceLookups($htmlView);
     $view = ['html' => $htmlView, 'text' => $textView];
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     $count = $this->mailer->send($view, $data, function (Message $m) use($data) {
         $to = ArrayUtils::get($data, 'to');
         $cc = ArrayUtils::get($data, 'cc');
         $bcc = ArrayUtils::get($data, 'bcc');
         $subject = ArrayUtils::get($data, 'subject');
         $fromName = ArrayUtils::get($data, 'from_name');
         $fromEmail = ArrayUtils::get($data, 'from_email');
         $replyName = ArrayUtils::get($data, 'reply_to_name');
         $replyEmail = ArrayUtils::get($data, 'reply_to_email');
         if (empty($fromEmail)) {
             $fromEmail = config('mail.from.address');
             $data['from_email'] = $fromEmail;
             if (empty($fromName)) {
                 $fromName = config('mail.from.name');
                 $data['from_name'] = $fromName;
             }
         }
         $to = EmailUtilities::sanitizeAndValidateEmails($to, 'swift');
         if (!empty($cc)) {
             $cc = EmailUtilities::sanitizeAndValidateEmails($cc, 'swift');
         }
         if (!empty($bcc)) {
             $bcc = EmailUtilities::sanitizeAndValidateEmails($bcc, 'swift');
         }
         $fromEmail = EmailUtilities::sanitizeAndValidateEmails($fromEmail, 'swift');
         if (!empty($replyEmail)) {
             $replyEmail = EmailUtilities::sanitizeAndValidateEmails($replyEmail, 'swift');
         }
         $m->to($to);
         if (!empty($fromEmail)) {
             $m->from($fromEmail, $fromName);
         }
         if (!empty($replyEmail)) {
             $m->replyTo($replyEmail, $replyName);
         }
         if (!empty($subject)) {
             Session::replaceLookups($subject);
             $m->subject(EmailUtilities::applyDataToView($subject, $data));
         }
         if (!empty($bcc)) {
             $m->bcc($bcc);
         }
         if (!empty($cc)) {
             $m->cc($cc);
         }
     });
     return $count;
 }
Ejemplo n.º 12
0
 /**
  * @param array $record
  *
  * @return array
  */
 public static function interpretRecordValues($record)
 {
     if (!is_array($record) || empty($record)) {
         return $record;
     }
     foreach ($record as $field => $value) {
         SessionUtility::replaceLookups($value);
         $record[$field] = $value;
     }
     return $record;
 }
Ejemplo n.º 13
0
 protected function setDriver($config)
 {
     $diskName = null;
     if (empty($config) || !isset($config['container'])) {
         $diskName = Config::get('filesystems.default');
     } else {
         $diskName = $config['container'];
     }
     if (empty($diskName)) {
         throw new InternalServerErrorException('Local file service driver/disk not configured. Please check configuration for file service - ' . $this->name . '.');
     }
     $disks = Config::get('filesystems.disks');
     if (!array_key_exists($diskName, $disks)) {
         throw new InternalServerErrorException('Local file service disk - ' . $diskName . ' not found.Please check configuration for file service - ' . $this->name . '.');
     }
     $disk = ArrayUtils::get($disks, $diskName);
     //  Replace any private lookups
     Session::replaceLookups($disk, true);
     if (!isset($disk['driver'])) {
         throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Driver not specified.');
     }
     switch ($disk['driver']) {
         case 'local':
             if (config('df.standalone')) {
                 $root = $disk['root'];
             } else {
                 $root = Managed::getStoragePath(config('df.local_file_service_container'));
             }
             if (!is_dir($root)) {
                 mkdir($root, 0775);
             }
             if (empty($root)) {
                 throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Root path not specified.');
             }
             if (!is_dir($root)) {
                 throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Root path not found.');
             }
             $this->driver = new LocalFileSystem($root);
             break;
         case 's3':
             $this->container = ArrayUtils::get($disk, 'bucket', ArrayUtils::get($disk, 'container'));
             ArrayUtils::set($disk, 'container', $this->container);
             if (empty($this->container)) {
                 throw new InternalServerErrorException('S3 file service bucket/container not specified. Please check configuration for file service - ' . $this->name);
             }
             $this->driver = new S3FileSystem($disk);
             break;
         case 'rackspace':
             $this->container = ArrayUtils::get($disk, 'container');
             if (empty($this->container)) {
                 throw new InternalServerErrorException('Azure blob container not specified. Please check configuration for file service - ' . $this->name);
             }
             $this->driver = new OpenStackObjectStorageSystem($disk);
             break;
         case 'azure':
             $this->container = ArrayUtils::get($disk, 'container');
             if (empty($this->container)) {
                 throw new InternalServerErrorException('Azure blob container not specified. Please check configuration for file service - ' . $this->name);
             }
             $this->driver = new AzureBlobFileSystem($disk);
             break;
         default:
             break;
     }
 }
 /**
  * @param array $config
  *
  * @throws InvalidArgumentException
  * @throws DfException
  */
 public function __construct($config)
 {
     $storageType = strtolower(ArrayUtils::get($config, 'storage_type'));
     $credentials = $config;
     $this->container = ArrayUtils::get($config, 'container');
     Session::replaceLookups($credentials, true);
     switch ($storageType) {
         case 'rackspace cloudfiles':
             $authUrl = ArrayUtils::get($credentials, 'url', 'https://identity.api.rackspacecloud.com/');
             $region = ArrayUtils::get($credentials, 'region', 'DFW');
             break;
         default:
             $authUrl = ArrayUtils::get($credentials, 'url');
             $region = ArrayUtils::get($credentials, 'region');
             break;
     }
     $username = ArrayUtils::get($credentials, 'username');
     $password = ArrayUtils::get($credentials, 'password');
     $apiKey = ArrayUtils::get($credentials, 'api_key');
     $tenantName = ArrayUtils::get($credentials, 'tenant_name');
     if (empty($authUrl)) {
         throw new InvalidArgumentException('Object Store authentication URL can not be empty.');
     }
     if (empty($username)) {
         throw new InvalidArgumentException('Object Store username can not be empty.');
     }
     $secret = ['username' => $username];
     if (empty($apiKey)) {
         if (empty($password)) {
             throw new InvalidArgumentException('Object Store credentials must contain an API key or a password.');
         }
         $secret['password'] = $password;
     } else {
         $secret['apiKey'] = $apiKey;
     }
     if (!empty($tenantName)) {
         $secret['tenantName'] = $tenantName;
     }
     if (empty($region)) {
         throw new InvalidArgumentException('Object Store region can not be empty.');
     }
     try {
         switch ($storageType) {
             case 'rackspace cloudfiles':
                 $pos = stripos($authUrl, '/v');
                 if (false !== $pos) {
                     $authUrl = substr($authUrl, 0, $pos);
                 }
                 $authUrl = FileUtilities::fixFolderPath($authUrl) . 'v2.0';
                 $os = new Rackspace($authUrl, $secret);
                 break;
             default:
                 $os = new OpenStack($authUrl, $secret);
                 break;
         }
         $this->blobConn = $os->ObjectStore('cloudFiles', $region);
         if (!$this->containerExists($this->container)) {
             $this->createContainer(['name' => $this->container]);
         }
     } catch (\Exception $ex) {
         throw new DfException('Failed to launch OpenStack service: ' . $ex->getMessage());
     }
 }
Ejemplo n.º 15
0
 /**
  * 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();
 }
Ejemplo n.º 16
0
 protected static function buildCriteriaArray($filter, $params = null, $ss_filters = null)
 {
     // interpret any parameter values as lookups
     $params = static::interpretRecordValues($params);
     // build filter array if necessary, add server-side filters if necessary
     if (!is_array($filter)) {
         Session::replaceLookups($filter);
         $criteria = static::buildFilterArray($filter, $params);
     } else {
         $criteria = $filter;
     }
     $serverCriteria = static::buildSSFilterArray($ss_filters);
     if (!empty($serverCriteria)) {
         $criteria = !empty($criteria) ? [$criteria, $serverCriteria] : $serverCriteria;
     }
     return $criteria;
 }
Ejemplo n.º 17
0
 /**
  * @param array  $headers
  * @param string $action
  * @param array  $options
  *
  * @return void
  */
 protected static function addHeaders($headers, $action, &$options)
 {
     if (null === ArrayUtils::get($options, CURLOPT_HTTPHEADER)) {
         $options[CURLOPT_HTTPHEADER] = [];
     }
     // DSP outbound headers, additional and pass through
     if (!empty($headers)) {
         foreach ($headers as $header) {
             if (static::doesActionApply($header, $action)) {
                 $name = ArrayUtils::get($header, 'name');
                 $value = ArrayUtils::get($header, 'value');
                 if (ArrayUtils::getBool($header, 'pass_from_client')) {
                     // Check for Basic Auth pulled into server variable already
                     if (0 === strcasecmp($name, 'Authorization') && (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']))) {
                         $value = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']);
                     } else {
                         $phpHeaderName = strtoupper(str_replace(['-', ' '], ['_', '_'], $name));
                         // check for non-standard headers (prefix HTTP_) and standard headers like Content-Type
                         $value = isset($_SERVER['HTTP_' . $phpHeaderName]) ? $_SERVER['HTTP_' . $phpHeaderName] : isset($_SERVER[$phpHeaderName]) ? $_SERVER[$phpHeaderName] : $value;
                     }
                 }
                 Session::replaceLookups($value, true);
                 $options[CURLOPT_HTTPHEADER][] = $name . ': ' . $value;
             }
         }
     }
 }