private function addConfigSettings(Collection $config)
 {
     foreach ($this->configSettings as $k => $v) {
         if (!$config->hasKey($k)) {
             $config->set($k, $v);
         }
     }
 }
Esempio n. 2
0
 public function createGuzzleClient(array $config)
 {
     $config = new Collection($config);
     $httpClient = new \GuzzleHttp\Client();
     $description = new Description($this->getDescription());
     $serializer = new Serializer($description, ['json_body' => new JsonBodyLocation('body')]);
     $client = new GuzzleClient($httpClient, $description, ['serializer' => $serializer]);
     $client->getEmitter()->attach(new Authorization($config->get('token'), $config->get('secret')));
     return $client;
 }
 public function __construct(ClientInterface $client = null, $config = null)
 {
     $this->client = $client;
     if ($config) {
         $this->config = Collection::fromConfig($config, ['client_secret' => '', 'scope' => ''], ['client_id', 'username', 'password']);
     }
 }
Esempio n. 4
0
 public static function factory($options = array())
 {
     $defaultOptions = array('base_url' => self::getDefaultServiceUrl(), 'defaults' => array('exceptions' => false, 'connect_timeout' => 10, 'timeout' => 60));
     //        $requiredOptions = array();
     //
     //        foreach ($requiredOptions as $optionName) {
     //            if (!isset($options[$optionName]) || $options[$optionName] === '') {
     //                throw new Exception\InvalidArgumentException(
     //                    sprintf('Missing required configuration option "%s"', $optionName)
     //                );
     //            }
     //        }
     $config = Collection::fromConfig($options, $defaultOptions);
     $headers = array('Accept' => 'application/json', 'User-Agent' => 'denner-client/' . self::CLIENT_VERSION);
     if (isset($options['app_id'])) {
         $headers['App-ID'] = $options['app_id'];
     }
     if (isset($options['app_key'])) {
         $headers['App-Key'] = $options['app_key'];
     }
     $httpClient = new HttpClient($config->toArray());
     $httpClient->setDefaultOption('headers', $headers);
     $httpClient->getEmitter()->attach(new Subscriber\ErrorHandler());
     $serviceDescriptionFile = __DIR__ . sprintf('/ServiceDescription/%s.php', self::getServiceDescriptionName());
     if (!file_exists($serviceDescriptionFile)) {
         throw new Exception\RuntimeException(sprintf('Service description does not exist at "%s"', $serviceDescriptionFile));
     }
     $description = new ServiceDescription(require $serviceDescriptionFile);
     $client = new static($httpClient, $description);
     return $client;
 }
Esempio n. 5
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$name) {
         $name = new CleanName($name);
     }
     parent::__construct($data);
 }
Esempio n. 6
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$passport) {
         $passport = new CleanPassport($passport);
     }
     parent::__construct($data);
 }
 public function __construct(ClientInterface $client = null, $config = null)
 {
     $this->client = $client;
     if ($config) {
         $this->config = Collection::fromConfig($config, ['grant_type' => 'client_credentials', 'client_secret' => '', 'scope' => ''], ['client_id']);
     }
 }
Esempio n. 8
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$email) {
         $email = new CleanEmail($email);
     }
     parent::__construct($data);
 }
 public static function factory($options = array())
 {
     $defaultOptions = array('base_url' => 'https://lw-inside.detailnet.ch/api/', 'defaults' => array('exceptions' => false, 'connect_timeout' => 10, 'timeout' => 60));
     //        $requiredOptions = array();
     //
     //        foreach ($requiredOptions as $optionName) {
     //            if (!isset($options[$optionName]) || $options[$optionName] === '') {
     //                throw new Exception\InvalidArgumentException(
     //                    sprintf('Missing required configuration option "%s"', $optionName)
     //                );
     //            }
     //        }
     $config = Collection::fromConfig($options, $defaultOptions);
     $headers = array('Accept' => 'application/json', 'User-Agent' => 'lw-inside-client/' . self::CLIENT_VERSION);
     if (isset($options['app_id'])) {
         $headers['App-ID'] = $options['app_id'];
     }
     if (isset($options['app_key'])) {
         $headers['App-Key'] = $options['app_key'];
     }
     $httpClient = new HttpClient($config->toArray());
     $httpClient->setDefaultOption('headers', $headers);
     $httpClient->getEmitter()->attach(new Subscriber\ErrorHandler());
     $description = new ServiceDescription(require __DIR__ . '/ServiceDescription/Inside.php');
     $client = new self($httpClient, $description);
     return $client;
 }
 public function __construct(ClientInterface $client = null, $config = null)
 {
     $this->client = $client;
     if ($config) {
         $this->config = Collection::fromConfig($config, ['client_secret' => '', 'refresh_token' => '', 'scope' => ''], ['client_id']);
     }
 }
Esempio n. 11
0
 /**
  * Create a OVH subscriber
  *
  * @param array $config Configuration array containing these parameters:
  *     - string version
  */
 public function __construct($config)
 {
     $this->config = Collection::fromConfig($config, array('application_key' => 'anonymous', 'application_secret' => 'anonymous', 'consumer_key' => 'anonymous'), array('application_key', 'application_secret', 'consumer_key'));
     $this->applicationKey = $this->config['application_key'];
     $this->applicationSecret = $this->config['application_secret'];
     $this->consumerKey = $this->config['consumer_key'];
 }
Esempio n. 12
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$address) {
         $address = new CleanAddress($address);
     }
     parent::__construct($data);
 }
Esempio n. 13
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$date) {
         $date = new CleanDate($date);
     }
     parent::__construct($data);
 }
Esempio n. 14
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$phone) {
         $phone = new CleanPhone($phone);
     }
     parent::__construct($data);
 }
Esempio n. 15
0
 public function __construct(array $data)
 {
     foreach ($data as $key => &$vehicle) {
         $vehicle = new CleanVehicle($vehicle);
     }
     parent::__construct($data);
 }
 /**
  * Creates a new AuthTokenFetcher plugin.
  *
  * @param FetchAuthTokenInterface $fetcher is used to fetch the auth token
  * @param array $cacheConfig configures the cache
  * @param CacheInterface $cache (optional) caches the token.
  */
 public function __construct(FetchAuthTokenInterface $fetcher, array $cacheConfig = null, CacheInterface $cache = null)
 {
     $this->fetcher = $fetcher;
     if (!is_null($cache)) {
         $this->cache = $cache;
         $this->cacheConfig = Collection::fromConfig($cacheConfig, ['lifetime' => self::DEFAULT_CACHE_LIFETIME, 'prefix' => ''], []);
     }
 }
 /**
  * Create a new ViewRangerClient
  *
  * @param string $apiKey
  * @param array  $config
  *
  * @return ViewRangerClientInterface
  * @throws \Exception
  */
 public static function create($apiKey, $config = [])
 {
     $defaults = ['base_url' => 'https://api.viewranger.com/public/v1', 'defaults' => ['query' => ['format' => 'json', 'key' => $apiKey], 'headers' => ['User-Agent' => 'ViewRangerClient']]];
     $config = Collection::fromConfig($config, $defaults, []);
     $config = $config->toArray();
     $client = new Client($config);
     return new static($client, new ViewRangerDescription());
 }
Esempio n. 18
0
 public function __construct(Config $config)
 {
     $defaultOptions = ['scheme' => 'http'];
     $requiredOptions = ['hostname'];
     $options = ['hostname' => $config->getHostname(), 'scheme' => $config->getUseSsl() ? 'https' : 'http', 'port' => $config->getPort()];
     $options = Collection::fromConfig($options, $defaultOptions, $requiredOptions);
     $this->client = new Client(['base_url' => ['{scheme}://{hostname}:{port}/api/', $options->toArray()], 'defaults' => ['auth' => [$config->getLogin(), $config->getPassword()], 'expect' => false, 'headers' => ['Accept' => 'application/json', 'User-Agent' => 'Openl10n ' . Client::getDefaultUserAgent()]]]);
     $this->registerDefaultEntryPoints();
 }
Esempio n. 19
0
 public function __construct(Config $config)
 {
     $defaultOptions = ['scheme' => 'https', 'version' => 'v1'];
     $requiredOptions = ['hostname'];
     $options = ['hostname' => $config->getHostname(), 'scheme' => $config->getUseSsl() ? 'https' : 'http', 'port' => $config->getPort(), 'version' => $config->getVersion()];
     $options = Collection::fromConfig($options, $defaultOptions, $requiredOptions);
     $this->client = new Client(['base_url' => ['{scheme}://{hostname}:{port}/api/{version}/', $options->toArray()], 'defaults' => ['headers' => ['Content-Type' => 'application/json'], 'auth' => [$config->getLogin(), $config->getPassword()]]]);
     $this->registerDefaultEntryPoints();
 }
Esempio n. 20
0
 /**
  * Creates a Message object from an array of raw message data
  *
  * @param array $data The message data
  *
  * @return Message
  * @throws \InvalidArgumentException If a valid type is not provided or there are other required keys missing
  */
 public static function fromArray(array $data)
 {
     // Make sure the type key is set
     if (!isset($data['Type'])) {
         throw new \InvalidArgumentException('The "Type" key must be ' . 'provided to instantiate a Message object.');
     }
     // Determine required keys and create a collection from the message data
     $requiredKeys = array_merge(self::$requiredKeys['__default'], isset(self::$requiredKeys[$data['Type']]) ? self::$requiredKeys[$data['Type']] : []);
     $data = Collection::fromConfig($data, [], $requiredKeys);
     return new self($data);
 }
Esempio n. 21
0
 /**
  * Instantiates a new SyneriseTracker instance.
  * @param array $config
  */
 public function __construct($config = array())
 {
     if (isset($config['allowFork']) && $config['allowFork'] == true) {
         $config['handler'] = new ForkCurlHandler([]);
     }
     parent::__construct($config);
     $this->client = Producers\Client::getInstance();
     $this->event = Event::getInstance();
     $this->transaction = Producers\Transaction::getInstance();
     $config = Collection::fromConfig($config, static::getDefaultConfig(), static::$required);
     $this->configure($config);
 }
Esempio n. 22
0
 public function __construct(RequestInterface $request, ResponseInterface $response)
 {
     $payload = $response->json();
     $this->id = $payload['id'];
     $result = $payload['result'];
     $this->status = [];
     if (isset($result['status'])) {
         $this->status = $result['status'];
         unset($result['status']);
     }
     parent::__construct($result);
 }
 /**
  * Creates a new ScopedAccessToken plugin.
  *
  * @param object $tokenFunc a token generator function
  * @param array|string scopes the token authentication scopes
  * @param cacheConfig configuration for the cache when it's present
  * @param object $cache an implementation of CacheInterface
  */
 public function __construct(callable $tokenFunc, $scopes, array $cacheConfig, CacheInterface $cache = NULL)
 {
     $this->tokenFunc = $tokenFunc;
     if (!(is_string($scopes) || is_array($scopes))) {
         throw new \InvalidArgumentException('wants scope should be string or array');
     }
     $this->scopes = $scopes;
     if (!is_null($cache)) {
         $this->cache = $cache;
         $this->cacheConfig = Collection::fromConfig($cacheConfig, ['lifetime' => self::DEFAULT_CACHE_LIFETIME, 'prefix' => ''], []);
     }
 }
Esempio n. 24
0
 /**
  * @param array            $config
  *     Possible configuration keys are:
  *     - accounts (string): The endpoint URL for the accounts API.
  *     - client_id (string): The OAuth2 client ID for this client.
  *     - debug (bool): Whether or not Guzzle debugging should be enabled
  *       (default: false).
  *     - verify (bool): Whether or not SSL verification should be enabled
  *       (default: true).
  *     - user_agent (string): The HTTP User-Agent for API requests.
  *     - cache (array|bool): Caching. Set to true to enable in-memory
  *       caching, to false (the default) to disable caching, or to an array
  *       of options as expected by the Guzzle cache subscriber.
  *     - proxy (array|string): A proxy setting, passed to Guzzle directly.
  *       Use a string to specify an HTTP proxy, or an array to specify
  *       different proxies for different protocols.
  * @param SessionInterface $session
  */
 public function __construct(array $config = [], SessionInterface $session = null)
 {
     $version = '0.1.x';
     $url = 'https://github.com/platformsh/platformsh-client-php';
     $defaults = ['accounts' => 'https://marketplace.commerceguys.com/api/platform/', 'client_id' => 'platformsh-client-php', 'client_secret' => '', 'debug' => false, 'verify' => true, 'user_agent' => "Platform.sh-Client-PHP/{$version} (+{$url})", 'cache' => false, 'token_url' => '/oauth2/token', 'proxy' => null];
     $this->config = Collection::fromConfig($config, $defaults);
     $this->session = $session ?: new Session();
     if (isset($this->config['api_token'])) {
         $this->setApiToken($this->config['api_token']);
         unset($this->config['api_token']);
     }
 }
Esempio n. 25
0
 /**
  * Create a new instance of GitlabClient.
  * @param array $config
  * @return GitlabGuzzleClient
  */
 public static function createClient($config = [])
 {
     $default = ['ssl.certificate_authority' => 'system'];
     $required = ['base_url', 'api_token'];
     $config = Collection::fromConfig($config, $default, $required);
     $config['base_url'] = self::completeBaseUrl($config['base_url']);
     $serviceDescriptionFilePath = __DIR__ . '/ServiceDescription/service_description.yml';
     $definition = self::loadServiceDefinition($serviceDescriptionFilePath);
     self::emulateGuzzle3ResponseModels($definition);
     $description = new Description($definition);
     $client = new Client($config->toArray());
     $client->setDefaultOption('headers/accept', 'application/json');
     $privateTokenPlugin = new PrivateTokenPlugin($config['api_token']);
     $client->getEmitter()->attach($privateTokenPlugin);
     $gitlabClient = new GitlabGuzzleClient($client, $description);
     $gitlabClient->getEmitter()->attach(new ResponseClassProcessor($description));
     return $gitlabClient;
 }
Esempio n. 26
0
 /**
  * Prepares the POST object to be utilzed to build a POST form.
  *
  * @return PostObject
  */
 public function prepareData()
 {
     // Validate required options
     $options = Collection::fromConfig($this->data, ['ttd' => '+1 hour', 'key' => '^${filename}']);
     $ttd = $this->pluckTtd($options);
     // If a policy or policy callback were provided, extract those from
     // the options.
     $rawJsonPolicy = $options['policy'];
     $policyCallback = $options['policy_callback'];
     unset($options['policy'], $options['policy_callback']);
     // Setup policy document
     $policy = ['expiration' => gmdate('Y-m-d\\TH:i:s\\Z', $ttd), 'conditions' => [['bucket' => $this->bucket]]];
     // Setup basic form
     $this->formAttributes = ['action' => $this->generateUrl($options), 'method' => 'POST', 'enctype' => 'multipart/form-data'];
     $this->formInputs = ['AWSAccessKeyId' => $this->client->getCredentials()->getAccessKeyId()];
     // Add success action status
     $status = (int) $options->get('success_action_status');
     if ($status && in_array($status, [200, 201, 204])) {
         $this->formInputs['success_action_status'] = (string) $status;
         $policy['conditions'][] = ['success_action_status' => (string) $status];
         unset($options['success_action_status']);
     }
     // Add other options
     foreach ($options as $key => $value) {
         $value = (string) $value;
         if ($value[0] === '^') {
             $value = substr($value, 1);
             $this->formInputs[$key] = $value;
             $value = preg_replace('/\\$\\{(\\w*)\\}/', '', $value);
             $policy['conditions'][] = ['starts-with', '$' . $key, $value];
         } else {
             $this->formInputs[$key] = $value;
             $policy['conditions'][] = [$key => $value];
         }
     }
     // Handle the policy
     $policy = is_callable($policyCallback) ? $policyCallback($policy, $this) : $policy;
     $this->jsonPolicy = $rawJsonPolicy ?: json_encode($policy);
     $this->applyPolicy();
     return $this;
 }
 public static function factory($config = [])
 {
     $default = [];
     $required = ['apikey'];
     foreach ($required as $value) {
         if (empty($config[$value])) {
             throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
         }
     }
     $config = Collection::fromConfig($config, $default, $required);
     $baseClient = new Client($config->toArray());
     $baseClient->setDefaultOption('query', ['apikey' => urldecode($config['apikey'])]);
     $description = new Description(static::getServiceDescription());
     $serializer = new Serializer($description, ['put' => new PutLocation('put')]);
     $client = new static($baseClient, $description, ['serializer' => $serializer]);
     $client->getEmitter()->on('prepared', function (PreparedEvent $event) {
         $request = $event->getTransaction()->request;
         if (!$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', 'application/json');
         }
     });
     return $client;
 }
Esempio n. 28
0
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = [])
 {
     $defaults = ['write_key' => null, 'version' => 'v1', 'batching' => 'request', 'log_file' => null, 'max_queue_size' => 10000, 'batch_size' => 100];
     // Create Configuration
     $config = Collection::fromConfig($config, $defaults, ['write_key', 'version', 'batching']);
     // Load versioned Service Description
     $description = $this->loadServiceDescription(__DIR__ . '/Description/segment.io.%s.php', $config->get('version'));
     // Allow the Adapter to be set
     $httpConfig = $config->hasKey('adapter') ? ['adapter' => $config->get('adapter')] : [];
     // Create the Client
     parent::__construct(new HttpClient($httpConfig), $description, $config->toArray());
     // Set Basic Auth
     $this->getHttpClient()->setDefaultOption('auth', [$config->get('write_key'), null]);
     // Set the content type header to use "application/json" for all requests
     $this->getHttpClient()->setDefaultOption('headers', array('Content-Type' => 'application/json'));
     // Default the Version
     $this->setConfig('defaults/version', $this->getDescription()->getApiVersion());
     if ($config->get('batching') == 'request') {
         $this->getEmitter()->attach(new BatchRequestSubscriber($this->getDescription(), ['max_queue_size' => $config->get('max_queue_size'), 'batch_size' => $config->get('batch_size')]));
     }
     if ($config->get('batching') == 'file') {
         $this->getEmitter()->attach(new BatchFileSubscriber($this->getDescription(), ['filename' => $config->get('log_file')]));
     }
 }
Esempio n. 29
0
 /**
  * @param array $config
  * @param ClientInterface|null $client
  * @param DescriptionInterface|null $description
  */
 public function __construct(array $config = [], ClientInterface $client = null, DescriptionInterface $description = null)
 {
     $mandatoryAttributes = ['api_token'];
     // unless a definition is explicitly provided, the base url is mandatory.
     if (!$description) {
         $mandatory[] = 'base_url';
     }
     // Create a collection object with defaults and required params set
     $config = Collection::fromConfig($config, ['max_retries' => 3], $mandatoryAttributes);
     if (!$client) {
         $client = $this->loadHttpClient($config);
     }
     if (!$description) {
         $description = $this->loadDescription($config);
     }
     // KLUDGE
     // hold on to the authentication subscriber
     // so we can update the JWT on it later in case
     // refreshApiToken() gets run.
     // TODO: look for a more elegant solution to this problem.
     // [ST 2015/07/24]
     $this->auth = $this->attachAuthenticationSubscriber($client, $config->get('api_token'));
     parent::__construct($client, $description, $config->toArray());
 }
Esempio n. 30
0
 /**
  * Create a new OAuth 1.0 plugin.
  *
  * The configuration array accepts the following options:
  *
  * - request_method: Consumer request method. One of 'header' or 'query'.
  *   Defaults to 'header'.
  * - callback: OAuth callback
  * - consumer_key: Consumer key string. Defaults to "anonymous".
  * - consumer_secret: Consumer secret. Defaults to "anonymous".
  * - token: Client token
  * - token_secret: Client secret token
  * - verifier: OAuth verifier.
  * - version: OAuth version. Defaults to '1.0'.
  * - realm: OAuth realm.
  * - signature_method: Signature method. One of 'HMAC-SHA1', 'RSA-SHA1', or
  *   'PLAINTEXT'. Defaults to 'HMAC-SHA1'.
  *
  * @param array $config Configuration array.
  */
 public function __construct($config)
 {
     $this->config = Collection::fromConfig($config, ['version' => '1.0', 'request_method' => self::REQUEST_METHOD_HEADER, 'consumer_key' => 'anonymous', 'consumer_secret' => 'anonymous', 'signature_method' => self::SIGNATURE_METHOD_HMAC], ['signature_method', 'version', 'consumer_key', 'consumer_secret']);
 }