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


PHP Client::getEventDispatcher方法代码示例

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


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

示例1: __construct

 public function __construct()
 {
     $this->client = new \Guzzle\Service\Client();
     $this->client->getEventDispatcher()->addListener('request.error', function (\Guzzle\Common\Event $event) {
         $event->stopPropagation();
     });
 }
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:7,代码来源:ChromediaGlobalRequest.php

示例2: __construct

 /**
  * Constructor
  *
  * @param string $accessToken
  */
 public function __construct($accessToken)
 {
     $this->accessToken = $accessToken;
     $this->client = new Client();
     $this->client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/config/service.json'));
     $this->client->getEventDispatcher()->addListener('client.create_request', [$this, 'onClientCreateRequest']);
     $this->client->getEventDispatcher()->addListener('request.error', [$this, 'onRequestError']);
 }
开发者ID:cocoiti,项目名称:qiita-php,代码行数:13,代码来源:Qiita.php

示例3: testRetrievesResponse

 /**
  * @covers Geocoder\HttpAdapter\GuzzleHttpAdapter::__construct
  * @covers Geocoder\HttpAdapter\GuzzleHttpAdapter::getContent
  */
 public function testRetrievesResponse()
 {
     $historyPlugin = new HistoryPlugin();
     $mockPlugin = new MockPlugin(array(new Response(200, null, 'body')));
     $client = new Client();
     $client->getEventDispatcher()->addSubscriber($mockPlugin);
     $client->getEventDispatcher()->addSubscriber($historyPlugin);
     $adapter = new GuzzleHttpAdapter($client);
     $this->assertEquals('body', $adapter->getContent('http://test.com/'));
     $this->assertEquals('http://test.com/', $historyPlugin->getLastRequest()->getUrl());
 }
开发者ID:socloz,项目名称:geocoder,代码行数:15,代码来源:GuzzleHttpAdapterTest.php

示例4: __construct

 /**
  * @param array $options API options
  */
 public function __construct($authToken, $options = array())
 {
     $apiBase = isset($options['api_base']) ? $options['api_base'] : 'https://api.webpay.jp/v1';
     $this->client = new GuzzleClient($apiBase);
     $this->client->setDefaultOption('headers/Authorization', 'Bearer ' . $authToken);
     $this->client->setDefaultOption('headers/Content-Type', "application/json");
     $this->client->setDefaultOption('headers/Accept', "application/json");
     $this->client->setDefaultOption('headers/User-Agent', "Apipa-webpay/2.2.2 php");
     $this->client->setDefaultOption('headers/Accept-Language', "en");
     $this->client->getEventDispatcher()->addListener('request.error', array($this, 'onRequestError'));
     $this->client->getEventDispatcher()->addListener('request.exception', array($this, 'onRequestException'));
     $this->charge = new Charge($this);
     $this->customer = new Customer($this);
     $this->token = new Token($this);
     $this->event = new Event($this);
     $this->shop = new Shop($this);
     $this->recursion = new Recursion($this);
     $this->account = new Account($this);
 }
开发者ID:kojiyamauchi,项目名称:WebPayAndPayPalAPISampleInWordPress,代码行数:22,代码来源:WebPay.php

示例5: testExecutesCommandsWithArray

 public function testExecutesCommandsWithArray()
 {
     $client = new Client('http://www.test.com/');
     $client->getEventDispatcher()->addSubscriber(new MockPlugin(array(new Response(200), new Response(200))));
     // Create a command set and a command
     $set = array(new MockCommand(), new MockCommand());
     $client->execute($set);
     // Make sure it sent
     $this->assertTrue($set[0]->isExecuted());
     $this->assertTrue($set[1]->isExecuted());
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:11,代码来源:ClientTest.php

示例6: getInfo

 public function getInfo($key, $default = null)
 {
     syslog(LOG_INFO, "getting info for key {$key} on request " . $_SERVER['REQUEST_URI']);
     if (empty($this->info)) {
         $this->info = array();
         syslog(LOG_INFO, 'guzzle start for url ' . $this->url);
         $guzzle = new GuzzleClient($this->url);
         $guzzle->getEventDispatcher()->addListener('request.error', function (Event $event) {
             $event->stopPropagation();
         });
         $response = $guzzle->head()->send();
         if (!$response->isSuccessful()) {
             $response = $guzzle->get()->send();
         }
         if ($response->isSuccessful()) {
             $this->info = $response->getInfo();
         }
         syslog(LOG_INFO, 'guzzle stop for url ' . $this->url);
     }
     return isset($this->info[$key]) ? $this->info[$key] : $default;
 }
开发者ID:dragonito,项目名称:mental-note,代码行数:21,代码来源:Info.php

示例7: setMockResponse

 /**
  * Set a mock response from a mock file on the next client request.
  *
  * This method assumes that mock response files are located under the
  * Command/Mock/ directory of the Service being tested
  * (e.g. Unfuddle/Command/Mock/).  A mock response is added to the next
  * request sent by the client.
  *
  * @param Client $client Client object to modify
  * @param string $paths  Path to files within the Mock folder of the service
  *
  * @return MockPlugin returns the created mock plugin
  */
 public function setMockResponse(Client $client, $paths)
 {
     $this->requests = array();
     $that = $this;
     $mock = new MockPlugin(null, true);
     $client->getEventDispatcher()->removeSubscriber($mock);
     $mock->getEventDispatcher()->addListener('mock.request', function (Event $event) use($that) {
         $that->addMockedRequest($event['request']);
     });
     foreach ((array) $paths as $path) {
         $mock->addResponse($this->getMockResponse($path));
     }
     $client->getEventDispatcher()->addSubscriber($mock);
     return $mock;
 }
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:28,代码来源:GuzzleTestCase.php

示例8: testCanAddListenerToParseDomainObjects

 public function testCanAddListenerToParseDomainObjects()
 {
     $client = new Client();
     $client->setDescription(ServiceDescription::factory(array('operations' => array('test' => array('responseClass' => 'FooBazBar')))));
     $foo = new \stdClass();
     $client->getEventDispatcher()->addListener('command.parse_response', function ($e) use($foo) {
         $e['result'] = $foo;
     });
     $command = $client->getCommand('test');
     $command->prepare()->setResponse(new Response(200), true);
     $result = $command->execute();
     $this->assertSame($result, $foo);
 }
开发者ID:rahilmomin,项目名称:ci_bootstrap_3,代码行数:13,代码来源:OperationResponseParserTest.php

示例9: testExecutesCommandSets

 /**
  * @covers Guzzle\Service\Client::execute
  */
 public function testExecutesCommandSets()
 {
     $client = new Client('http://www.test.com/');
     $client->getEventDispatcher()->addSubscriber(new MockPlugin(array(new Response(200))));
     // Create a command set and a command
     $set = new CommandSet();
     $cmd = new MockCommand();
     $set->addCommand($cmd);
     $this->assertSame($set, $client->execute($set));
     // Make sure it sent
     $this->assertTrue($cmd->isExecuted());
     $this->assertTrue($cmd->isPrepared());
     $this->assertEquals(200, $cmd->getResponse()->getStatusCode());
 }
开发者ID:norv,项目名称:guzzle,代码行数:17,代码来源:ClientTest.php

示例10: setMockResponse

 /**
  * Set a mock response from a mock file on the next client request.
  *
  * This method assumes that mock response files are located under the
  * Command/Mock/ directory of the Service being tested
  * (e.g. Unfuddle/Command/Mock/).  A mock response is added to the next
  * request sent by the client.
  *
  * @param Client $client Client object to modify
  * @param string $paths  Path to files within the Mock folder of the service
  *
  * @return MockPlugin returns the created mock plugin
  */
 public function setMockResponse(Client $client, $paths)
 {
     $this->requests = array();
     $that = $this;
     $mock = new MockPlugin(null, true);
     $client->getEventDispatcher()->removeSubscriber($mock);
     $mock->getEventDispatcher()->addListener('mock.request', function (Event $event) use($that) {
         $that->addMockedRequest($event['request']);
     });
     if ($paths instanceof Response) {
         // A single response instance has been specified, create an array with that instance
         // as the only element for the following loop to work as expected
         $paths = array($paths);
     }
     foreach ((array) $paths as $path) {
         $mock->addResponse($this->getMockResponse($path));
     }
     $client->getEventDispatcher()->addSubscriber($mock);
     return $mock;
 }
开发者ID:ChenOhayon,项目名称:sitepoint_codes,代码行数:33,代码来源:GuzzleTestCase.php


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