本文整理汇总了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();
});
}
示例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']);
}
示例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());
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}