本文整理汇总了PHP中self::addSubscriber方法的典型用法代码示例。如果您正苦于以下问题:PHP self::addSubscriber方法的具体用法?PHP self::addSubscriber怎么用?PHP self::addSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类self
的用法示例。
在下文中一共展示了self::addSubscriber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
/**
* Factory method to create a new TogglClient
*
* The following array keys and values are available options:
* - base_url: Base URL of web service
* - username: username or API key
* - password: password (if empty, then username is a API key)
*
* See https://www.toggl.com/public/api#api_token for more information on the api token
*
* @param array|Collection $config Configuration data
*
* @return self
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://www.toggl.com/api/{apiVersion}', 'debug' => false, 'apiVersion' => 'v8', 'api_key' => '', 'username' => '', 'password' => '');
$required = array('api_key', 'username', 'password', 'base_url', 'apiVersion');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
// Attach a service description to the client
if ($config->get('apiVersion') == 'v8') {
$description = ServiceDescription::factory(__DIR__ . '/services_v8.json');
} else {
die('Only v8 is supported at this time');
}
$client->setDescription($description);
$client->setDefaultHeaders(array("Content-type" => "application/json"));
if (!empty($config->get('api_key'))) {
$config->set('username', $config->get('api_key'));
$config->set('password', 'api_token');
}
if (empty($config->get('password'))) {
$config->set('password', 'api_token');
}
$authPlugin = new CurlAuthPlugin($config->get('username'), $config->get('password'));
$client->addSubscriber($authPlugin);
if ($config->get('debug')) {
$client->addSubscriber(LogPlugin::getDebugPlugin());
}
return $client;
}
示例2: factory
/**
* factory
*
* @param array $config
* @return \self
*/
public static function factory($config = [])
{
$default = ['useClientCert' => false, 'domain' => "cybozu.com", 'logfile' => __DIR__ . '/../../../app/logs/kintone.log', 'useLog' => true];
$required = ['domain', 'subdomain', 'login', 'password'];
$config = Collection::fromConfig($config, $default, $required);
$client = new self(parent::getApiPathBase($config), $config);
$client->addSubscriber(new KintoneAuth($config->toArray()));
$client->addSubscriber(new KintoneError($config->toArray()));
$client->setDescription(ServiceDescription::factory(__DIR__ . "/Resources/config/kintone.json"));
if ($config->get('useLog')) {
$logPlugin = LogPlugin::getDebugPlugin(TRUE, fopen($config->get('logfile'), 'a'));
$client->addSubscriber($logPlugin);
}
return $client;
}
示例3: factory
/**
* @param string $serviceDescription
* @param array $config
* @return \Guzzle\Service\Client
*/
public static function factory($config = array())
{
if (!isset($config['serviceDescription'])) {
throw new \Exception("Cannot create a twuzzle client without a service description");
}
$oauthConfig = array();
if (!isset($config['consumerKey'])) {
throw new \Exception("Cannot create an twuzzle client without a consumer key");
} else {
$oauthConfig['consumer_key'] = $config['consumerKey'];
}
if (!isset($config['consumerSecret'])) {
throw new \Exception("Cannot create an twuzzle client without a consumer secret");
} else {
$oauthConfig['consumer_secret'] = $config['consumerSecret'];
}
if (isset($config['token']) && !empty($config['token'])) {
$oauthConfig['token'] = $config['token'];
}
if (isset($config['tokenSecret']) && !empty($config['tokenSecret'])) {
$oauthConfig['token_secret'] = $config['tokenSecret'];
}
$client = new self();
$client->setDescription(ServiceDescription::factory($config['serviceDescription']));
$oauth = new OauthPlugin($oauthConfig);
$client->addSubscriber($oauth);
return $client;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: factory
/**
* Factory method to create a new TogglClient
*
* The following array keys and values are available options:
* - base_url: Base URL of web service
* - api_key: API key
*
* See https://www.toggl.com/public/api#api_token for more information on the api token
*
* @param array|Collection $config Configuration data
*
* @return ReportsClient
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://www.toggl.com/reports/api/{apiVersion}', 'debug' => false, 'apiVersion' => 'v2');
$required = array('api_key', 'base_url', 'apiVersion');
$config = Collection::fromConfig($config, $default, $required);
$serviceDescriptionFile = __DIR__ . '/reporting_' . $config->get('apiVersion') . '.json';
$description = ServiceDescription::factory($serviceDescriptionFile);
$client = new self($config->get('base_url'), $config);
$client->setDescription($description);
$client->setDefaultHeaders(array("Content-type" => "application/json"));
$authPlugin = new CurlAuthPlugin($config->get('api_key'), 'api_token');
$client->addSubscriber($authPlugin);
if ($config->get('debug')) {
$client->addSubscriber(LogPlugin::getDebugPlugin());
}
return $client;
}
示例8: factory
/**
* Factory Method to build new Client
*
* @param array $config
* @return MeetupOAuthClient
*/
public static function factory($config = array())
{
$configuration = static::buildConfig($config);
$client = new self($configuration->get('base_url'), $configuration);
$client->addSubscriber(new OauthPlugin(array('consumer_key' => $configuration->get('consumer_key'), 'consumer_secret' => $configuration->get('consumer_secret'), 'token' => $configuration->get('token'), 'token_secret' => $configuration->get('token_secret'))));
static::loadDefinitions($client);
static::toggleRateLimitingPlugin($client, $config);
return $client;
}
示例9: factory
/**
* Factory Method to build new Client
*
* @param array $config
* @return MeetupKeyAuthClient
*/
public static function factory($config = array())
{
$configuration = static::buildConfig($config);
$client = new self($configuration->get('base_url'), $configuration);
$client->addSubscriber(new KeyAuthPlugin($configuration->get('key')));
static::loadDefinitions($client);
static::toggleRateLimitingPlugin($client, $config);
return $client;
}
示例10: factory
public static function factory($config = array())
{
$default = array();
$required = array('base_url', 'consumer_key', 'consumer_secret', 'token', 'token_secret');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$client->addSubscriber(new OauthPlugin($config->toArray()));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/../service/basekit.json'));
return $client;
}
示例11: factory
public static function factory($config = array())
{
$resolver = new OptionsResolver();
static::setDefaultOptions($resolver);
$config = $resolver->resolve($config);
$client = new self($config['base_url'], array('request.options' => array('headers' => array('Content-Type' => 'application/json'))));
$client->addSubscriber(new Plugin($config['application_key'], $config['application_secret'], $config['consumer_key']));
$client->setDescription(ServiceDescription::factory(realpath(__DIR__ . '/../../../config/description.json')));
return $client;
}
示例12: 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;
}
示例13: factory
/**
* Create an instance of the client
*
* @param array $config
*
* @return \GuzzleAmazonWebservices\ProductAdvertising
*/
public static function factory($config = array())
{
$defaults = array('base_url' => '{{scheme}}://{{locale}}/onca/xml', 'scheme' => 'http', 'locale' => self::LOCALE_US, 'version' => self::VERSION);
$required = array('access_key', 'secret_key', 'associate_tag');
$config = Inspector::prepareConfig($config, $defaults, $required);
$signature = new SignatureV2($config->get('access_key'), $config->get('secret_key'));
$client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), $config->get('associate_tag'), $config->get('version'));
$client->setConfig($config);
$client->addSubscriber(new SignaturePlugin($signature, $config->get('version')));
return $client;
}
示例14: factory
/**
* Factory method to create a new BlimpClient
*
* The following array keys and values are available options:
* - base_url: Base URL of web service
* - username: API username
* - password: API password
*
* @param array|Collection $config Configuration data
*
* @return self
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://go.urbanairship.com/api/');
$required = array('base_url', 'appKey', 'appSecret');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/service.php');
$client->setDescription($description);
$client->addSubscriber(new CurlAuthPlugin($config->get('appKey'), $config->get('appSecret')));
return $client;
}
示例15: factory
public static function factory($config = array())
{
$defaults = array('base_url' => 'https://api.twitter.com/{version}/', 'version' => '1.1');
$required = array('base_url', 'version', 'consumer_key', 'consumer_secret', 'token', 'token_secret');
$config = Collection::fromConfig($config, $defaults, $required);
$client = new self($config->get('base_url'), $config);
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/client.json');
$client->setDescription($description);
$client->addSubscriber(new OauthPlugin(array('consumer_key' => $config['consumer_key'], 'consumer_secret' => $config['consumer_secret'], 'token' => $config['token'], 'token_secret' => $config['token_secret'])));
return $client;
}