當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。