当前位置: 首页>>代码示例>>PHP>>正文


PHP ClientInterface::getEmitter方法代码示例

本文整理汇总了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);
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:10,代码来源:Operator.php

示例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);
 }
开发者ID:kyandersen73,项目名称:sms2,代码行数:9,代码来源:ServiceTest.php

示例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();
     });
 }
开发者ID:fideloper,项目名称:DigitalOceanV2,代码行数:16,代码来源:Guzzle5Adapter.php

示例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));
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:16,代码来源:Client.php

示例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;
 }
开发者ID:alxmsl,项目名称:mediawiki-api-base,代码行数:22,代码来源:MediawikiApi.php

示例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);
 }
开发者ID:gunnartorfis,项目名称:plex_requests,代码行数:19,代码来源:GuzzleAdapter.php

示例7: attachKey

 public function attachKey(ClientInterface $http, $key)
 {
     $subscriber = new SimpleSubscriber(['key' => $key]);
     $http->setDefaultOption('auth', 'simple');
     $http->getEmitter()->attach($subscriber);
     return $http;
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:7,代码来源:Guzzle5AuthHandler.php

示例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;
 }
开发者ID:sitedyno,项目名称:phergie-irc-plugin-react-twitter,代码行数:17,代码来源:Plugin.php

示例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);
     }
 }
开发者ID:joecampo,项目名称:mediawiki-api-base,代码行数:8,代码来源:MediawikiApi.php

示例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);
 }
开发者ID:buldezir,项目名称:FacebookAuthenticationAdapter,代码行数:10,代码来源:GuzzleFacebookApiTest.php

示例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;
 }
开发者ID:assistechnologie,项目名称:firebase-php-1,代码行数:13,代码来源:Firebase.php

示例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);
 }
开发者ID:bdunogier,项目名称:guzzle-site-authenticator,代码行数:14,代码来源:AuthenticatorSubscriberSpec.php

示例13: mockResponses

 protected function mockResponses(\GuzzleHttp\ClientInterface &$client, array $responses)
 {
     $client->getEmitter()->attach(new Mock($responses));
 }
开发者ID:eelkevdbos,项目名称:openexchangerates-php,代码行数:4,代码来源:OpenExchangeRatesTest.php

示例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;
 }
开发者ID:ilios,项目名称:php-api-client,代码行数:12,代码来源:Client.php

示例15: registerAuthSubscriber

 protected function registerAuthSubscriber($credentials)
 {
     $subscriber = new Oauth1($credentials);
     $this->client->getEmitter()->attach($subscriber);
 }
开发者ID:vdbf,项目名称:magento-rest-php,代码行数:5,代码来源:Connector.php


注:本文中的GuzzleHttp\ClientInterface::getEmitter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。