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


PHP Client::getEventDispatcher方法代码示例

本文整理汇总了PHP中Guzzle\Http\Client::getEventDispatcher方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getEventDispatcher方法的具体用法?PHP Client::getEventDispatcher怎么用?PHP Client::getEventDispatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Client的用法示例。


在下文中一共展示了Client::getEventDispatcher方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addDebugOptionsToHttpClient

 public static function addDebugOptionsToHttpClient(Client $guzzleClient)
 {
     $guzzleClient->setDefaultOption('debug', true);
     $echoCb = function (Event $event) {
         echo (string) $event['request'] . PHP_EOL;
         echo (string) $event['response'] . PHP_EOL;
     };
     $guzzleClient->getEventDispatcher()->addListener('request.complete', $echoCb);
     $guzzleClient->getEventDispatcher()->addListener('request.exception', $echoCb);
 }
开发者ID:xsolla,项目名称:xsolla-sdk-php,代码行数:10,代码来源:DebugHelper.php

示例2: getGuzzle

 protected function getGuzzle()
 {
     $this->historyPlugin = new HistoryPlugin();
     $this->mockPlugin = new MockPlugin();
     $this->mockPlugin->addResponse(new GuzzleResponse(200, null, '<html><body><p>Hi</p></body></html>'));
     $guzzle = new GuzzleClient('', array('redirect.disable' => true));
     $guzzle->getEventDispatcher()->addSubscriber($this->mockPlugin);
     $guzzle->getEventDispatcher()->addSubscriber($this->historyPlugin);
     return $guzzle;
 }
开发者ID:gargallo,项目名称:tfs-test,代码行数:10,代码来源:ClientTest.php

示例3: shouldAuthenticateUsingAllGivenParameters

 /**
  * @test
  * @dataProvider getAuthenticationFullData
  */
 public function shouldAuthenticateUsingAllGivenParameters($site, $login, $password)
 {
     $client = new GuzzleClient();
     $listeners = $client->getEventDispatcher()->getListeners('request.before_send');
     $this->assertCount(1, $listeners);
     $httpClient = new HttpClient(array(), $client);
     $httpClient->authenticate($site, $login, $password);
     $listeners = $client->getEventDispatcher()->getListeners('request.before_send');
     $this->assertCount(2, $listeners);
     $authListener = $listeners[1][0];
     $this->assertInstanceOf('Eloqua\\HttpClient\\Listener\\AuthListener', $authListener);
 }
开发者ID:tableau-mkt,项目名称:elomentary,代码行数:16,代码来源:HttpClientTest.php

示例4: setUp

 public function setUp()
 {
     $this->guzzleClient = new Client('http://[::1]:8999');
     global $argv;
     if (in_array('--debug', $argv, true)) {
         $echoCb = function (Event $event) {
             echo (string) $event['request'] . PHP_EOL;
             echo (string) $event['response'] . PHP_EOL;
         };
         $this->guzzleClient->getEventDispatcher()->addListener('request.complete', $echoCb);
         $this->guzzleClient->getEventDispatcher()->addListener('request.exception', $echoCb);
     }
 }
开发者ID:apigraf,项目名称:xsolla-sdk-php,代码行数:13,代码来源:ServerTest.php

示例5: getClient

 protected function getClient($response, $code = 200, $throwCurlException = false)
 {
     $plugin = new MockPlugin();
     $plugin->addResponse(new Response($code, null, $response));
     $clientHttp = new GuzzleClient('http://my.domain.tld/api/v1');
     $clientHttp->getEventDispatcher()->addSubscriber($plugin);
     if ($throwCurlException) {
         $clientHttp->getEventDispatcher()->addListener('request.before_send', function (\Guzzle\Common\Event $event) {
             throw new \Guzzle\Http\Exception\CurlException();
         });
     }
     $logger = new Logger('tests');
     $logger->pushHandler(new NullHandler());
     return new Client('123456', '654321', new GuzzleAdapter($clientHttp), $logger);
 }
开发者ID:nlegoff,项目名称:Phraseanet-PHP-SDK,代码行数:15,代码来源:Repository.php

示例6: createClient

 private function createClient()
 {
     $client = new Client($this->getBaseUrl());
     $client->getEventDispatcher()->addListener('request.error', static function (Event $event) {
         $event->stopPropagation();
     });
     return $client;
 }
开发者ID:internations,项目名称:http-mock,代码行数:8,代码来源:Server.php

示例7: executeRequest

 /**
  * @param Url $url
  * @return \Guzzle\Http\Message\Response
  */
 protected function executeRequest(Url $url)
 {
     $guzzle = new GuzzleClient();
     $guzzle->getEventDispatcher()->addListener('request.error', function (Event $event) {
         if ($event['response']->getStatusCode() != 200) {
             $event->stopPropagation();
         }
     });
     return $guzzle->createRequest('GET', $url)->send();
 }
开发者ID:jdecoster,项目名称:SlackBundle,代码行数:14,代码来源:Client.php

示例8: setAuthHeader

 /**
  * Sets the authorization header provided by the token 
  * 
  * @param Array token Array with token info
  * @return Void
  */
 protected function setAuthHeader(array $token)
 {
     $this->configs = array_merge($this->configs, $token);
     if (!empty($this->configs['access_token'])) {
         $authorization = sprintf('Bearer %s', $this->configs['access_token']);
         $this->client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
             $event['request']->addHeader('Authorization', $authorization);
         });
     }
 }
开发者ID:bigset1,项目名称:blueridge,代码行数:16,代码来源:OAuth.php

示例9: test_cache_configuration_config_present

 /**
  * Sanity check to make sure that OoyalaCache is a subscriber.
  *
  * The only reason this is needed is because the plugin might be disabled
  * because of configuration, so it's good to check when some configuration
  * is present that the plugin actually does not remove itself as a subscriber.
  */
 public function test_cache_configuration_config_present()
 {
     $client = new Client('http://test.com', array('ooyala.cache' => true));
     $plugin = new OoyalaCache();
     $className = get_class($plugin);
     $client->addSubscriber($plugin);
     $client->getEventDispatcher()->dispatch(OoyalaClient::EVENT_INITIALIZED, new Event(array('client' => $client)));
     $subscribedEvents = array_keys(OoyalaCache::getSubscribedEvents());
     foreach ($client->getEventDispatcher()->getListeners() as $eventName => $listeners) {
         if (!in_array($eventName, $subscribedEvents)) {
             continue;
         }
         $actual = array();
         foreach ($listeners as $listener) {
             $actual[] = get_class($listener[0]);
         }
         $this->assertTrue(in_array($className, $actual));
     }
 }
开发者ID:sheknows,项目名称:ooyala-api-client,代码行数:26,代码来源:OoyalaCacheTest.php

示例10: testAddMixpanelAuthentication

 public function testAddMixpanelAuthentication()
 {
     $plugin = new MixGuzzleAuthPlugin('key', 'secret');
     $client = new Client('http://test.com/');
     $client->getEventDispatcher()->addSubscriber($plugin);
     $request = $client->get('/');
     $event = new Event(array('request' => $request, 'timestamp' => 123456789));
     $params = $plugin->onRequestBeforeSend($event);
     $this->assertArrayHasKey('sig', $params);
 }
开发者ID:jlinn,项目名称:mixguzzle,代码行数:10,代码来源:MixGuzzleAuthPluginTest.php

示例11: create

 /**
  * Creates the GuzzleTeleporter
  *
  * @return GuzzleTeleporter
  */
 public static function create()
 {
     $client = new Client();
     $client->getEventDispatcher()->addListener('request.error', function (Event $event) {
         // override guzzle default behavior of throwing exceptions
         // when 4xx & 5xx responses are encountered
         $event->stopPropagation();
     }, -254);
     $client->addSubscriber(BackoffPlugin::getExponentialBackoff(5, array(500, 502, 503, 408)));
     return new static($client);
 }
开发者ID:schnommus,项目名称:sebholzapfel.com,代码行数:16,代码来源:GuzzleTeleporter.php

示例12: testAddPsrLoggerToClient

 public function testAddPsrLoggerToClient()
 {
     $client = new Client();
     $listenersBefore = $client->getEventDispatcher()->getListeners('request.sent');
     $logger = $this->getMockForAbstractClass('Psr\\Log\\LoggerInterface');
     $plugin = GuzzleClientHelper::addPsrLoggerToClient($client, $logger);
     $this->assertTrue($client->getEventDispatcher()->hasListeners('request.sent'));
     $expectedListenersCount = count($listenersBefore) + 1;
     $this->assertCount($expectedListenersCount, $client->getEventDispatcher()->getListeners('request.sent'));
     $this->assertContains([$plugin, 'onRequestSent'], $client->getEventDispatcher()->getListeners('request.sent'));
 }
开发者ID:subscribo,项目名称:omnipay-subscribo-shared,代码行数:11,代码来源:GuzzleClientHelperTest.php

示例13: testAddsDigestAuthentication

 public function testAddsDigestAuthentication()
 {
     $plugin = new CurlAuthPlugin('julian', 'test', CURLAUTH_DIGEST);
     $client = new Client('http://www.test.com/');
     $client->getEventDispatcher()->addSubscriber($plugin);
     $request = $client->get('/');
     $this->assertEquals('julian', $request->getUsername());
     $this->assertEquals('test', $request->getPassword());
     $this->assertEquals('julian:test', $request->getCurlOptions()->get(CURLOPT_USERPWD));
     $this->assertEquals(CURLAUTH_DIGEST, $request->getCurlOptions()->get(CURLOPT_HTTPAUTH));
 }
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:11,代码来源:CurlAuthPluginTest.php

示例14: testAddsWsseAuthenticationWithCustomDigest

 public function testAddsWsseAuthenticationWithCustomDigest()
 {
     $plugin = new WsseAuthPlugin('michael', 'test', function ($nonce, $created, $password) {
         return 'this_digest_wont_work';
     });
     $client = new Client('http://www.test.com/');
     $client->getEventDispatcher()->addSubscriber($plugin);
     $request = $client->get('/');
     $headers = $request->getHeaders();
     $this->assertTrue(false !== $headers->hasKey('Authorization'));
     $this->assertTrue(false !== $headers->hasKey('X-WSSE'));
     $this->assertTrue(false !== strpos(array_shift($headers->get('X-WSSE')), 'this_digest_wont_work'));
 }
开发者ID:davedevelopment,项目名称:guzzle-wsse-auth-plugin,代码行数:13,代码来源:WsseAuthPluginTest.php

示例15: testNotLimited

 public function testNotLimited()
 {
     // Create a script to return a 429 response like Desk.com
     $this->getServer()->flush();
     $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata"));
     $plugin = new BackoffPlugin($this->strategy());
     $client = new Client($this->getServer()->getUrl());
     $client->getEventDispatcher()->addSubscriber($plugin);
     $request = $client->get();
     $request->send();
     // Make sure it eventually completed successfully
     $this->assertEquals(200, $request->getResponse()->getStatusCode());
     $this->assertEquals('data', $request->getResponse()->getBody(true));
     // Check that two requests were made to retry this request
     $this->assertEquals(1, count($this->getServer()->getReceivedRequests(false)));
     $this->assertEquals(0, $request->getParams()->get(BackoffPlugin::RETRY_PARAM));
 }
开发者ID:dh-open,项目名称:desk-php,代码行数:17,代码来源:StrategySystemTest.php


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