本文整理汇总了PHP中GuzzleHttp\ClientInterface::getEmitter方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::getEmitter方法的具体用法?PHP ClientInterface::getEmitter怎么用?PHP ClientInterface::getEmitter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::getEmitter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* {@inheritDoc}
*/
public function __construct(ClientInterface $client, ApiInterface $api)
{
$this->client = $client;
$this->api = $api;
$this->errorBuilder = new Builder();
$this->client->getEmitter()->attach($this->errorBuilder);
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$this->client = new Guzzle\Client();
$this->mock = new Guzzle\Subscriber\Mock();
$this->client->getEmitter()->attach($this->mock);
$this->service = new ServiceMock();
$this->service->setClient($this->client);
}
示例3: __construct
/**
* @param string $accessToken
* @param ClientInterface $client (optional)
* @param ExceptionInterface $exception (optional)
*/
public function __construct($accessToken, ClientInterface $client = null, ExceptionInterface $exception = null)
{
$that = $this;
$this->client = $client ?: new \GuzzleHttp\Client();
$this->exception = $exception;
$this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $accessToken));
$this->client->getEmitter()->on('complete', function (CompleteEvent $e) use($that) {
$that->handleResponse($e);
$e->stopPropagation();
});
}
示例4: __construct
/**
* @param $apiKey
* @param array $httpOptions
* @param HttpClientInterface $httpClient
*/
public function __construct($apiKey, array $httpOptions = [], HttpClientInterface $httpClient = null)
{
$this->httpOptions = array_merge($this->httpOptions, $httpOptions);
if (is_null($httpClient)) {
$httpClient = new \GuzzleHttp\Client($this->httpOptions);
}
$this->apiKey = $apiKey;
$this->httpClient = $httpClient;
$emitter = $this->httpClient->getEmitter();
$emitter->attach(new AuthHeaderSubscriber($apiKey));
}
示例5: __construct
/**
* @param string|ClientInterface $client Guzzle Client or api base url
* @param MediawikiSession|null $session Inject a custom session here
*
* @throws InvalidArgumentException
*/
public function __construct($client, $session = null)
{
if (is_string($client)) {
$client = new Client(array('base_url' => $client, 'defaults' => array('headers' => array('User-Agent' => 'addwiki-guzzle-mediawiki-client'))));
} elseif (!$client instanceof ClientInterface) {
throw new InvalidArgumentException('$client must either be a string or ClientInterface instance');
}
if ($session === null) {
$session = new MediawikiSession($this);
} elseif (!$session instanceof MediawikiSession) {
throw new InvalidArgumentException('$session must either me null or MediawikiSession instance');
}
$this->client = $client;
$this->client->getEmitter()->attach(new Cookie(new CookieJar()));
$this->session = $session;
}
示例6: registerSubscribers
/**
* {@inheritDoc}
*/
public function registerSubscribers(EventDispatcherInterface $eventDispatcher)
{
$filter = RetrySubscriber::createChainFilter([RetrySubscriber::createIdempotentFilter(), RetrySubscriber::createStatusFilter([429, 500, 503])]);
$retry = new RetrySubscriber(['filter' => $filter, 'delay' => function ($number, $event) {
/** @var \GuzzleHttp\Message\Response $response */
if (null !== $event->getResponse() && $event->getResponse()->getStatusCode() === 429) {
// Adding 20% of the waiting time as it seems to be the best result without getting two blocking reqs.
$sleep = (int) $event->getResponse()->getHeader('retry-after') * 1.2;
if ($sleep >= 0) {
return $sleep * 1000;
}
}
return 0;
}, 'max' => 3]);
$this->client->getEmitter()->attach($retry);
}
示例7: attachKey
public function attachKey(ClientInterface $http, $key)
{
$subscriber = new SimpleSubscriber(['key' => $key]);
$http->setDefaultOption('auth', 'simple');
$http->getEmitter()->attach($subscriber);
return $http;
}
示例8: getHttpClient
/**
* Returns a configured HTTP client.
*
* The client is instantiated lazily to allow the event loop to be injected
* into the instance of this class so that it can be used here by the
* client adapter.
*
* @return \GuzzleHttp\ClientInterface
*/
protected function getHttpClient()
{
if (!$this->httpClient) {
$this->httpClient = new Client(array('base_url' => 'https://api.twitter.com/1.1/', 'adapter' => new HttpClientAdapter($this->eventLoop)));
$this->httpClient->getEmitter()->attach($this->oauth);
}
return $this->httpClient;
}
示例9: attachLoggingRetrySubscribersToClient
private function attachLoggingRetrySubscribersToClient()
{
foreach ($this->getRetryFilters() as $filter) {
$subscriber = new RetrySubscriber(array('filter' => RetrySubscriber::createLoggingDelay($filter, $this->logger)));
$this->clientSubscribers[] = $subscriber;
$this->client->getEmitter()->attach($subscriber);
}
}
示例10: mockResponse
private function mockResponse($status, $body = null)
{
$mock = new Mock();
if ($status === 200) {
$mock->addResponse(new Response($status, array(), $body === null ? null : Stream::factory($body)));
} else {
$mock->addException(new RequestException('Exception', new Request('GET', 'http://graph.facebook.com/xyz')));
}
$this->guzzleClient->getEmitter()->attach($mock);
}
示例11: batch
public function batch($callable)
{
//enable batching in the config
$this->setOption('batch', true);
//gather requests
call_user_func_array($callable, array($this));
$requests = $this->requests;
$emitter = $this->client->getEmitter();
$emitter->emit('requests.batched', new RequestsBatchedEvent($requests));
//reset the requests for the next batch
$this->requests = [];
return $requests;
}
示例12: let
function let(SiteConfigBuilder $siteConfigBuilder, SiteConfig $siteConfig, Factory $authenticatorFactory, ClientInterface $guzzle, Emitter $emitter, BeforeEvent $beforeEvent, CompleteEvent $completeEvent, RequestInterface $request, ResponseInterface $response, Factory $authenticatorFactory)
{
$siteConfig->getHost()->willReturn('example.com');
$siteConfigBuilder->buildForHost('example.com')->willReturn($siteConfig);
$guzzle->getEmitter()->willReturn($emitter);
$request->getHost()->willReturn('example.com');
$beforeEvent->getRequest()->willReturn($request);
$beforeEvent->getClient()->willReturn($guzzle);
$response->getBody()->willReturn('<html></html>');
$completeEvent->getResponse()->willReturn($response);
$completeEvent->getRequest()->willReturn($request);
$completeEvent->getClient()->willReturn($guzzle);
$this->beConstructedWith($siteConfigBuilder, $authenticatorFactory);
}
示例13: mockResponses
protected function mockResponses(\GuzzleHttp\ClientInterface &$client, array $responses)
{
$client->getEmitter()->attach(new Mock($responses));
}
示例14: attachAuthenticationSubscriber
/**
* @param ClientInterface $client
* @param string $token
* @return JwtAuth
*/
protected function attachAuthenticationSubscriber(ClientInterface $client, $token)
{
// create and attach JWT auth subscriber
$auth = new JwtAuth($token);
$client->getEmitter()->attach($auth);
return $auth;
}
示例15: registerAuthSubscriber
protected function registerAuthSubscriber($credentials)
{
$subscriber = new Oauth1($credentials);
$this->client->getEmitter()->attach($subscriber);
}