本文整理汇总了PHP中self::setDefaultOption方法的典型用法代码示例。如果您正苦于以下问题:PHP self::setDefaultOption方法的具体用法?PHP self::setDefaultOption怎么用?PHP self::setDefaultOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类self
的用法示例。
在下文中一共展示了self::setDefaultOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: factory
/**
* Static factory method used to turn an array or collection of configuration data into an instantiated object.
*
* @param array|Collection $config Configuration data
* @return KinveyClient
*/
public static function factory($config = array())
{
$client = new self($config['baseURL'], $config);
$client->setDefaultOption('headers/Content-Type', 'application/json');
$client->setDefaultOption('X-Kinvey-API-Version', 2);
$client->setAuthMode($config['defaultAuthMode']);
$client = self::registerPlugins($client);
return $client;
}
示例3: 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;
}
示例4: 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;
}
示例5: factory
/**
* Creates a client token auth client with the supplied configuration options
*
* @param array $config
* @return Client|IntercomBasicAuthClient
*/
public static function factory($config = [])
{
$client = new self();
$config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
$client->configure($config);
$client->setBasicAuth($config->get('client_uuid'), $config->get('client_key'));
$client->setDefaultOption('query/app_id', $config->get('app_id'));
return $client;
}
示例6: factory
/**
* Creates a client token auth client with the supplied configuration options
*
* @param array $config
* @return Client|IntercomBasicAuthClient
*/
public static function factory($config = array())
{
$client = new self();
$config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
$client->configure($config);
$client->setBasicAuth($config->get('client_uuid'), $config->get('client_key'));
$client->setUserAgent('intercom-php/1.4.0', true);
$client->setDefaultOption('query/app_id', $config->get('app_id'));
return $client;
}
示例7: factory
public static function factory($config = array())
{
$config = Collection::fromConfig($config, self::getDefaultConfig(), ['api_token', 'service_description']);
$client = new self($config->get('base_url'), $config);
$client->setDescription($client->getServiceDescriptionFromFile($config->get('service_description')));
$client->setDefaultOption('auth', [$config->get('api_token'), null, 'basic']);
$client->addSubscriber($client);
$client->setErrorHandler();
return $client;
}
示例8: factory
/**
* Factory method to create a new Bitpay client
*
* @param array $config
*
* @return BitpayClient
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://bitpay.com/api');
$required = array('apiKey');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json'));
$client->setDefaultOption('auth', array($config['apiKey'], '', 'Basic'));
return $client;
}
示例9: factory
public static function factory($config = array())
{
$default = array('base_url' => '');
$required = array('base_url', 'scheme', 'auth_token', 'service');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$description = ServiceDescription::factory(__DIR__ . '/Resources/search.json');
$client->setDescription($description);
$client->setDefaultOption('query', array('auth_token' => $config->get('auth_token')));
return $client;
}
示例10: factory
/**
* {@inheritDoc}
*/
public static function factory($config = array())
{
$defaultOptions = array('base_url' => '{scheme}://{hostname}', 'hostname' => 'api.mgrt.net', 'scheme' => 'https');
$requiredOptions = array('public_key', 'private_key');
$config = Collection::fromConfig($config, $defaultOptions, $requiredOptions);
$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('auth', array($config['public_key'], $config['private_key'], 'Basic'));
$client->setDescription($description);
$client->setUserAgent(sprintf('mgrt-php/%s guzzle/%s PHP/%s', \Mgrt\Version::VERSION, \Guzzle\Common\Version::VERSION, PHP_VERSION));
return $client;
}
示例11: factory
/**
* Factory method to create the client
*
* @param array $config
* @return Client|SparkreelClient
*/
public static function factory($config = array())
{
$default = array('base_url' => '{scheme}://{hostname}/v1', 'scheme' => 'https', 'hostname' => 'api.sparkreel.com');
$required = array('base_url', 'api_key');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
// set X-API-Key header
$client->setDefaultOption('headers/X-API-Key', $config->get('api_key'));
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/v0.json');
$client->setDescription($description);
return $client;
}
示例12: factory
/**
* Factory method to create the client
*
* @param array $config
* @return Client
*/
public static function factory($config = array())
{
$default = array('base_url' => '{scheme}://{hostname}/oauth', 'scheme' => 'https', 'hostname' => 'www.sparkreel.com');
$required = array('base_url', 'client_id', 'client_secret');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
// Attach a service description to the client
$description = ServiceDescription::factory(dirname(__DIR__) . '/Resources/OAuth2.json');
$client->setDescription($description);
// send client_id & client_secret as Basic auth
$client->setDefaultOption('auth', array($config->get('client_id'), $config->get('client_secret'), 'Basic'));
return $client;
}
示例13: factory
public static function factory($config = array())
{
$default = array('host' => 'api.trak.io/v1', 'https' => true);
$config = array_merge($config, $default);
$required = array('token', 'host', 'https');
self::validate($required, $config);
$config = Collection::fromConfig($config, $default, $required);
$client = new self(($config->get('https') ? 'https://' : 'http://') . $config->get('host'), $config);
$client->setDefaultOption('headers/X-Token', $config->get('token'));
$config->hasKey('distinct_id') ? $client->distinct_id($config->get('distinct_id')) : null;
$config->hasKey('channel') ? $client->channel($config->get('channel')) : null;
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/config/client.json'));
return $client;
}
示例14: factory
public static function factory($config = array())
{
// Provide a hash of default client configuration options
$default = array('base_url' => 'https://maps.googleapis.com/maps/api/place');
// The following values are required when creating the client
$required = array('key');
// Merge in default settings and validate the config
$config = Collection::fromConfig($config, $default, $required);
// Create a new Google Places API Client
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('query', array('key' => $config['key'], 'language' => $config['language']));
// Set the service description
$client->setDescription(ServiceDescription::factory(__DIR__ . '/../config/service_description.json'));
return $client;
}
示例15: factory
public static function factory($config = array())
{
$default = array('base_url' => 'https://api.foursquare.com/v2/');
$required = array('client_id', 'client_secret');
foreach ($required as $value) {
if (empty($config[$value])) {
throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
}
}
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('query', array('client_id' => $config['client_id'], 'client_secret' => $config['client_secret'], 'v' => '20130707'));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/../Resources/config/client.json'));
return $client;
}