本文整理汇总了PHP中Guzzle\Http\ClientInterface::addSubscriber方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::addSubscriber方法的具体用法?PHP ClientInterface::addSubscriber怎么用?PHP ClientInterface::addSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::addSubscriber方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $projectname
* @param string $username
* @param string $password
* @param ClientInterface $httpClient
*/
public function __construct($projectname, $username, $password, ClientInterface $httpClient = null)
{
$this->projectname = $projectname;
$this->username = $username;
$this->password = $password;
$this->httpClient = $httpClient ?: new GuzzleClient();
$this->httpClient->addSubscriber($this);
}
示例2: __construct
/**
* @param ClientInterface $client Client object
*/
public function __construct(ClientInterface $client = null)
{
$this->requests = array();
if (!$client) {
$this->client = new Client();
$cache = new CachePlugin(array('storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new FilesystemCache(sys_get_temp_dir())))));
$this->client->addSubscriber($cache);
} else {
$this->client = $client;
}
}
示例3: setUp
protected function setUp()
{
Phake::initAnnotations($this);
Phake::when($this->cryptService)->encryptRSA(Phake::anyParameters())->thenReturn($this->rsaEncrypted);
Phake::when($this->cryptService)->sign(Phake::anyParameters())->thenReturn($this->signed);
Phake::when($this->cache)->get(GuzzleApiService::CACHE_KEY_PUBLIC_KEY)->thenReturn($this->publicKey);
$this->guzzleClient = new Client();
$this->guzzleMockPlugin = new MockPlugin();
$this->guzzleClient->addSubscriber($this->guzzleMockPlugin);
$this->apiService = new GuzzleApiService($this->appKey, $this->secretKey, $this->guzzleClient, $this->cryptService, $this->cache, 999999);
$this->loggingApiService = new GuzzleApiService($this->appKey, $this->secretKey, $this->guzzleClient, $this->cryptService, $this->cache, 999999, $this->logger);
}
示例4: __construct
public function __construct(ClientInterface $client = null)
{
$this->client = $client;
if (!$this->client) {
$this->client = new Client();
$this->client->getEventDispatcher()->addListener('request.error', function (Event $event) {
// override guzzle default behavior of throwing exceptions
// when 4xx & 5xx responses are encountered
$event->stopPropagation();
}, -254);
$this->client->addSubscriber(BackoffPlugin::getExponentialBackoff(5, array(500, 502, 503, 408)));
}
}
示例5: __construct
/**
* @param array $configs
* @param ClientInterface $client
* @param LoggerInterface $logger
*/
protected function __construct(array $configs, ClientInterface $client = null, LoggerInterface $logger = null)
{
$configs = array_merge($this->getDefaultConfig(), $configs);
$this->setCredentials($configs);
$this->setDefaults();
if ($configs['auth_in_header']) {
$this->headers['Authorization'] = $this->getAuthHeader();
}
$this->logger = $logger ?: new NullLogger();
$this->client = $client ?: new Client();
$this->client->setBaseUrl($configs['base_url']);
$this->client->addSubscriber(new LogPlugin(new PsrLogAdapter($this->logger)));
$this->tokenRequestPath = $configs['token_request_path'];
}
示例6: __construct
/**
* Constructor.
*
* @param ClientInterface $httpClient
* @param array $options
* @param LoggerInterface $logger
*/
public function __construct(ClientInterface $httpClient, array $options, LoggerInterface $logger = null)
{
$this->httpClient = $httpClient;
$scheme = isset($options['scheme']) ? $options['scheme'] : static::DEFAULT_SCHEME;
$host = isset($options['host']) ? $options['host'] : static::DEFAULT_HOST;
$port = isset($options['port']) ? $options['port'] : static::DEFAULT_PORT;
$pathPrefix = isset($options['path_prefix']) ? $options['path_prefix'] : static::DEFAULT_PATH_PREFIX;
$accessKey = isset($options['access_key']) ? $options['access_key'] : null;
$secretKey = isset($options['secret_key']) ? $options['secret_key'] : null;
$this->scheme = $scheme;
$this->host = $host;
$this->port = $port;
$this->pathPrefix = $pathPrefix;
$this->accessKey = $accessKey;
$this->secretKey = $secretKey;
$this->companyName = isset($options['company']) ? $options['company'] : null;
$this->collectionName = isset($options['collection']) ? $options['collection'] : null;
$this->options = $options;
$this->logger = $logger;
$exceptionFactory = new NamespaceExceptionFactory(new EngineExceptionParser(), 'Sajari\\Engine\\Exception', 'Sajari\\Engine\\Exception\\EngineException');
$this->httpClient->addSubscriber(new StatusCodeListener());
$this->httpClient->addSubscriber(new ExceptionListener($exceptionFactory));
$connectTimeout = 10;
$timeout = 10;
if (isset($this->options['curl.options']['CURLOPT_CONNECTTIMEOUT'])) {
$connectTimeout = (int) $this->options['curl.options']['CURLOPT_CONNECTTIMEOUT'];
}
if (isset($this->options['curl.options']['CURLOPT_TIMEOUT'])) {
$timeout = (int) $this->options['curl.options']['CURLOPT_TIMEOUT'];
}
$this->httpClient->setBaseUrl(sprintf('%s://%s', $this->scheme, $this->host));
$this->httpClient->setConfig(array(HttpClient::SSL_CERT_AUTHORITY => false, HttpClient::CURL_OPTIONS => array(CURLOPT_CONNECTTIMEOUT => $connectTimeout, CURLOPT_TIMEOUT => $timeout)));
}
示例7: addPsrLoggerToClient
/**
* @param ClientInterface $client
* @param LoggerInterface $logger
* @param null|string $formatter
* @return LogPlugin
*/
public static function addPsrLoggerToClient(ClientInterface $client, LoggerInterface $logger, $formatter = self::SIMPLE_FORMAT)
{
$formatter = is_null($formatter) ? self::SIMPLE_FORMAT : $formatter;
$adapter = new PsrLogAdapter($logger);
$plugin = new LogPlugin($adapter, $formatter);
$client->addSubscriber($plugin);
return $plugin;
}
示例8: testGetByAccessToken_Invalid
public function testGetByAccessToken_Invalid()
{
$user = $this->createUser();
$this->user_service->save($user);
$mock_plugin = new \Guzzle\Plugin\Mock\MockPlugin();
$mock_plugin->addResponse(new \Guzzle\Http\Message\Response(200, [], json_encode(['id' => 2])));
$this->http->addSubscriber($mock_plugin);
$this->assertNull($this->user_service->getByAccessToken('invalid_token'));
}
示例9: setupOAuth2Plugin
/**
* setting up the oauth2 plugin for authorizing the requests
*/
private function setupOAuth2Plugin()
{
$oauth2AuthorizationClient = $this->resolveClient(null);
$oauth2AuthorizationClient->setBaseUrl(Properties::authorizationUrl());
$clientCredentials = new ClientCredentials($oauth2AuthorizationClient, $this->config->toArray());
$oauth2Plugin = new OAuth2Plugin($clientCredentials);
$oauth2Plugin->setCache($this->config->getAccessTokenCacheFile());
$this->client->addSubscriber($oauth2Plugin);
}
示例10: addSubscriber
/**
* Add a subscriber
*
* @param EventSubscriberInterface $subscriber
*/
public function addSubscriber(EventSubscriberInterface $subscriber)
{
$this->client->addSubscriber($subscriber);
}