本文整理汇总了PHP中Guzzle\Common\Collection::fromConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::fromConfig方法的具体用法?PHP Collection::fromConfig怎么用?PHP Collection::fromConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Common\Collection
的用法示例。
在下文中一共展示了Collection::fromConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(array $options)
{
$options = Collection::fromConfig($options, self::$defaultOptions, self::$requiredOptions);
$this->client = MeasurementProtocolClient::factory(array('ssl' => $options->get(self::OPT_SSL)));
$this->registerPlugin(new DataSetter(array(HitInterface::FIELD_VERSION => 1, HitInterface::FIELD_TRACKING_ID => $options->get(self::OPT_TRACKING_ID))));
$this->registerPlugins($options->get(self::OPT_PLUGINS));
}
示例2: factory
public static function factory($config = array())
{
if (isset($config['developer_mode']) && is_bool($config['developer_mode'])) {
$developerMode = $config['developer_mode'];
} else {
$developerMode = false;
}
$baseUrl = array('https://api.auspost.com.au', 'https://devcentre.auspost.com.au/myapi');
// Ignore unnecessary user-specified configuration values
if ($developerMode) {
unset($config['email_address']);
unset($config['password']);
}
unset($config['base_url']);
$default = array('developer_mode' => $developerMode, 'base_url' => $baseUrl[$developerMode], 'email_address' => 'anonymous@auspost.com.au', 'password' => 'password');
$required = array('developer_mode', 'base_url', 'email_address', "password");
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$client->getConfig()->setPath('request.options/headers/Authorization', 'Basic ' . base64_encode($config->get('email_address') . ':' . $config->get('password')));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/service.json'));
$client->setSslVerification(false);
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) {
$request = $event['request'];
$request->addCookie('OBBasicAuth', 'fromDialog');
});
return $client;
}
示例3: factory
public static function factory($config = array())
{
// The following values are required when creating the client
$required = array('base_url', 'username', 'password');
// Merge in default settings and validate the config
$config = Collection::fromConfig($config, array(), $required);
// Create a new sData client
$client = new self($config->get('base_url'), $config);
// JSON by default
$client->setDefaultOption('query/format', 'json');
// Authentication
$client->setDefaultOption('auth', array($config->get('username'), $config->get('password'), 'Basic'));
// Strip the BOM from results
$client->addSubscriber(new StripBomPlugin());
// Optional logging
if ($config->get('log')) {
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) {
$req = $event['request'];
\Log::info('sData', ['request' => $req->getMethod() . ' ' . $req->getResource()]);
});
}
// Set the service description
$services = \Config::get('sdata::services');
if (!empty($services)) {
$client->setDescription(ServiceDescription::factory($services));
}
// Done
return $client;
}
示例4: getConfigCollection
/**
* Gets Config Collection instance
*
* @param unknown $config
* @return \Guzzle\Common\Collection
*/
public static function getConfigCollection($config)
{
$default = array('base_url' => 'http://manage.encoding.com');
$required = array('userid', 'userkey');
$config = Collection::fromConfig($config, $default, array('base_url', 'userid', 'userkey'));
return $config;
}
示例5: factory
public static function factory($config = array(), $required = array())
{
if (!defined('static::ENDPOINT')) {
throw new Exception\ServiceEndpointException('A client must have an endpoint');
}
$default = array('base_url' => '{scheme}://{domain}/' . static::ENDPOINT);
$required = array_merge(array('scheme', 'domain', 'base_url'), $required);
$config = Collection::fromConfig($config, $default, $required);
$client = new static($config->get('base_url'), $config);
$refClass = new \ReflectionClass(get_called_class());
$serviceDefinitionPath = dirname($refClass->getFileName());
$classNamePieces = explode('\\', get_called_class());
$serviceDefinitionFile = array_pop($classNamePieces) . '.json';
switch (true) {
case is_readable(dirname($serviceDefinitionPath) . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $serviceDefinitionFile):
$serviceDefinition = $serviceDefinitionPath . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $serviceDefinitionFile;
break;
case is_readable($serviceDefinitionPath . DIRECTORY_SEPARATOR . $serviceDefinitionFile):
$serviceDefinition = $serviceDefinitionPath . DIRECTORY_SEPARATOR . $serviceDefinitionFile;
break;
default:
throw new Exception\ClientConfigurationException('A client must have a service definition. Could not read the file "' . $serviceDefinition . '"');
}
$description = ServiceDescription::factory($serviceDefinition);
$client->setDescription($description);
return $client;
}
示例6: factory
/**
* @param array $config
* @return \Guzzle\Service\Client|BasecampClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://basecamp.com/', 'version' => 'v1', 'token' => null, 'user_agent' => null, 'auth_method' => 'oauth');
$required = [];
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
if (empty($config['token'])) {
throw new InvalidArgumentException("Config must contain token when using oath");
}
$authorization = sprintf('Bearer %s', $config['token']);
if (!isset($authorization)) {
throw new InvalidArgumentException("Config must contain valid authentication method");
}
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client->setDescription($description);
// Set required User-Agent
$client->setUserAgent($config['user_agent']);
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
$event['request']->addHeader('Authorization', $authorization);
});
// Add cache plugin
$cachePlugin = new CachePlugin(['storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new ApcCache()))]);
$client->addSubscriber($cachePlugin);
return $client;
}
示例7: processConfig
/**
* Processes the configuration passed to self::factory()
*
* @param array|Guzzle\Common\Collection $config
*
* @return Guzzle\Common\Collection
*/
public function processConfig($config)
{
$required = array('authentication');
$default = array('api_version' => 2, 'base_url' => 'https://{subdomain}.desk.com/api/v{api_version}/');
$baseUrl = $default['base_url'];
if (isset($config['base_url'])) {
$baseUrl = $config['base_url'];
}
// Subdomain is required, if the base URL is the default (not
// set), or if it contains "{subdomain}" in it
if (strpos($baseUrl, '{subdomain}') !== false) {
$required[] = 'subdomain';
}
// Authentication is required, either OAuth or Basic
// If none specified, try to autodetect it
if (!isset($config['authentication'])) {
if (isset($config['username']) && isset($config['password'])) {
// If username and password are set, use basic auth
$config['authentication'] = 'basic';
} elseif (isset($config['consumer_key']) && isset($config['consumer_secret']) && isset($config['token']) && isset($config['token_secret'])) {
// Otherwise, use OAuth if we have enough data
$config['authentication'] = 'oauth';
}
}
return Collection::fromConfig($config, $default, $required);
}
示例8: __construct
/**
* @param array $config
* @param string $configSection
*/
public function __construct($config, $configSection = null)
{
$this->endpoint = $this->getConfigurationItem($config, $configSection, "endpoint");
$this->username = $this->getConfigurationItem($config, $configSection, "username");
$this->password = $this->getConfigurationItem($config, $configSection, "password");
$this->guzzleConfig = Collection::fromConfig(array("base_url" => $this->endpoint, "username" => $this->username, "password" => $this->password));
}
示例9: __construct
/**
* @param array $config
*/
public function __construct(array $config = array())
{
$defaults = array('conf_dir' => 'conf', 'conf_files' => array());
$required = array('conf_dir', 'conf_files');
$this->config = \Guzzle\Common\Collection::fromConfig($config, $defaults, $required);
$this->config['conf_dir'] = rtrim($this->config['conf_dir'], '/\\');
}
示例10: factory
/**
* @param array $config
* @return \Guzzle\Service\Client|BasecampClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://basecamp.com/{user_id}/api/{version}/', 'version' => 'v1', 'auth' => 'http', 'token' => null, 'username' => null, 'password' => null);
$required = array('user_id', 'app_name', 'app_contact');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
if ($config['auth'] === 'http') {
if (!isset($config['username'], $config['password'])) {
throw new InvalidArgumentException("Config must contain username and password when using http auth");
}
$authorization = 'Basic ' . base64_encode($config['username'] . ':' . $config['password']);
}
if ($config['auth'] === 'oauth') {
if (!isset($config['token'])) {
throw new InvalidArgumentException("Config must contain token when using oauth");
}
$authorization = sprintf('Bearer %s', $config['token']);
}
if (!isset($authorization)) {
throw new InvalidArgumentException("Config must contain valid authentication method");
}
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client->setDescription($description);
// Set required User-Agent
$client->setUserAgent(sprintf('%s (%s)', $config['app_name'], $config['app_contact']));
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
$event['request']->addHeader('Authorization', $authorization);
});
return $client;
}
示例11: factory
/**
* @param array $config
* @return \Guzzle\Service\Client|ImageRelayClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://{imagerelay_url}/api/v2/', 'imagerelay_url' => 'subdomain.imagerelay.com');
$config = Collection::fromConfig($config, $default);
$client = new self($config->get('base_url'), $config);
if ($config['auth'] === 'http') {
if (!isset($config['username'], $config['password'])) {
throw new InvalidArgumentException("Username and password required when using http auth.");
}
$authorization = 'Basic ' . base64_encode($config['username'] . ':' . $config['password']);
}
if ($config['auth'] === 'oauth') {
if (!isset($config['token'])) {
throw new InvalidArgumentException("Access token required when using oauth.");
}
$authorization = sprintf('Bearer %s', $config['token']);
}
if (!isset($authorization)) {
throw new InvalidArgumentException("Must use either http or oauth authentication method.");
}
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/api.php');
$client->setDescription($description);
// Set required User-Agent
$client->setUserAgent(sprintf('%s (%s)', $config['app_name'], $config['app_contact']));
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
$event['request']->addHeader('Authorization', $authorization);
});
return $client;
}
示例12: factory
/**
* {@inheritdoc}
*/
public static function factory($config = array())
{
$default = array('url' => false, 'munchkin_id' => false, 'version' => 1, 'bulk' => false);
$required = array('client_id', 'client_secret', 'version');
$config = Collection::fromConfig($config, $default, $required);
$url = $config->get('url');
if (!$url) {
$munchkin = $config->get('munchkin_id');
if (!$munchkin) {
throw new \Exception('Must provide either a URL or Munchkin code.');
}
$url = sprintf('https://%s.mktorest.com', $munchkin);
}
$grantType = new Credentials($url, $config->get('client_id'), $config->get('client_secret'));
$auth = new Oauth2Plugin($grantType);
if ($config->get('bulk') === true) {
$restUrl = sprintf('%s/bulk/v%d', rtrim($url, '/'), $config->get('version'));
} else {
$restUrl = sprintf('%s/rest/v%d', rtrim($url, '/'), $config->get('version'));
}
$client = new self($restUrl, $config);
$client->addSubscriber($auth);
$client->setDescription(ServiceDescription::factory(__DIR__ . '/service.json'));
$client->setDefaultOption('headers/Content-Type', 'application/json');
return $client;
}
示例13: factory
public static function factory($config = array())
{
// provide a hash of default client configuration options
$default = array('base_url' => 'http://127.0.0.1/', 'api_id' => 1, 'private_key' => 'fbdce19f94b158e72ae6020cc5126642a9d42d086419c015ad2b6dd429312410');
// the following values are required when creating the client
$required = array('base_url', 'api_id', 'private_key');
// merge in default settings and validate the config
$config = \Guzzle\Common\Collection::fromConfig($config, $default, $required);
// create a new client
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('headers/API_ID', $config->get('api_id'));
$client->getEventDispatcher()->addListener('client.create_request', function (\Guzzle\Common\Event $event) use($config) {
// Guzzle\Http\Message\Request
$data = $event['request']->getQuery();
// Guzzle\Http\Message\EntityEnclosingRequest
if ($event['request'] instanceof Guzzle\Http\Message\EntityEnclosingRequest) {
$data->overwriteWith($event['request']->getPostFields());
}
$time = (string) time();
$message = $time . $config->get('api_id') . implode($data->toArray());
$hash = hash_hmac('sha256', $message, $config->get('private_key'));
$event['request']->setHeader('API_TIME', $time)->setHeader('API_HASH', $hash);
unset($data, $time, $message, $hash);
});
return $client;
}
示例14: factory
/**
* {@inheritdoc}
*
* @return \Acquia\Network\AcquiaNetworkClient
*/
public static function factory($config = array())
{
$defaults = array('base_url' => 'https://rpc.acquia.com', 'server_address' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '', 'http_host' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'https' => false, 'network_id' => '', 'network_key' => '');
// Instantiate the Acquia Search plugin.
$config = Collection::fromConfig($config, $defaults);
return new static($config->get('base_url'), $config->get('network_id'), $config->get('network_key'), $config);
}
示例15: __construct
public function __construct($baseUrl = '', $config = null)
{
$default = array();
$required = array('apikey');
$config = Collection::fromConfig($config, $default, $required);
parent::__construct($baseUrl, $config);
}