本文整理汇总了PHP中Guzzle\Service\Client::getCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getCommand方法的具体用法?PHP Client::getCommand怎么用?PHP Client::getCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Service\Client
的用法示例。
在下文中一共展示了Client::getCommand方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAllowsForJsonBasedArrayParamsFunctionalTest
public function testAllowsForJsonBasedArrayParamsFunctionalTest()
{
$description = new ServiceDescription(array('operations' => array('test' => new Operation(array('httpMethod' => 'PUT', 'parameters' => array('data' => array('required' => true, 'filters' => 'json_encode', 'location' => 'body')))))));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('test', array('data' => array('foo' => 'bar')));
$request = $command->prepare();
$this->assertEquals('{"foo":"bar"}', (string) $request->getBody());
}
示例2: testAllowsForJsonBasedArrayParamsFunctionalTest
public function testAllowsForJsonBasedArrayParamsFunctionalTest()
{
$service = array('test' => new ApiCommand(array('method' => 'PUT', 'params' => array('data' => array('required' => true, 'type' => 'type:array', 'filters' => 'json_encode', 'location' => 'body')))));
$description = new ServiceDescription($service);
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('test', array('data' => array('foo' => 'bar')));
$request = $command->prepare();
$this->assertEquals(json_encode(array('foo' => 'bar')), (string) $request->getBody());
}
示例3: testValidatesAdditionalParameters
public function testValidatesAdditionalParameters()
{
$description = ServiceDescription::factory(array('operations' => array('foo' => array('httpMethod' => 'PUT', 'parameters' => array('bar' => array('location' => 'header')), 'additionalParameters' => array('location' => 'json')))));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('foo');
$command['bar'] = 'test';
$command['hello'] = 'abc';
$request = $command->prepare();
$this->assertEquals('test', (string) $request->getHeader('bar'));
$this->assertEquals('{"hello":"abc"}', (string) $request->getBody());
}
示例4: testVisitsLocationWithMultipleFiles
public function testVisitsLocationWithMultipleFiles()
{
$description = ServiceDescription::factory(array('operations' => array('DoPost' => array('httpMethod' => 'POST', 'parameters' => array('foo' => array('location' => 'postFile', 'type' => array('string', 'array')))))));
$this->getServer()->flush();
$this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length:0\r\n\r\n"));
$client = new Client($this->getServer()->getUrl());
$client->setDescription($description);
$command = $client->getCommand('DoPost', array('foo' => array(__FILE__, __FILE__)));
$command->execute();
$received = $this->getServer()->getReceivedRequests();
$this->assertContains('name="foo[0]";', $received[0]);
$this->assertContains('name="foo[1]";', $received[0]);
}
示例5: testValidatesAdditionalParameters
/**
* @expectedException \Guzzle\Service\Exception\ValidationException
* @expectedExceptionMessage Validation errors: [abc] must be of type string
*/
public function testValidatesAdditionalParameters()
{
$description = ServiceDescription::factory(array('operations' => array('foo' => array('parameters' => array('baz' => array('type' => 'integer')), 'additionalParameters' => array('type' => 'string')))));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('foo', array('abc' => false, 'command.headers' => array('foo' => 'bar')));
$command->prepare();
}
示例6: executeCommand
/**
* @param $command
* @param array $arguments
*
* @return array
*/
public function executeCommand($command, $arguments = array())
{
$command = $this->client->getCommand($command, $arguments);
return $this->client->execute($command);
/*$command->getResponse()->json();*/
}
示例7: testThrowsExceptionWhenMissingCommand
/**
* @expectedException InvalidArgumentException
*/
public function testThrowsExceptionWhenMissingCommand()
{
$client = new Client();
$mock = $this->getMock('Guzzle\\Service\\Command\\Factory\\FactoryInterface');
$mock->expects($this->any())->method('factory')->with($this->equalTo('test'))->will($this->returnValue(null));
$client->setCommandFactory($mock);
$client->getCommand('test');
}
示例8: testAllowsPostFieldsAndFiles
/**
* @covers Guzzle\Service\Command\DynamicCommand::build
*/
public function testAllowsPostFieldsAndFiles()
{
$service = new ServiceDescription(array('post_command' => new ApiCommand(array('method' => 'POST', 'uri' => '/key', 'params' => array('test' => array('location' => 'post_field'), 'test_2' => array('location' => 'post_field:foo'), 'test_3' => array('location' => 'post_file'))))));
$client = new Client('http://www.test.com/api/v2');
$client->setDescription($service);
$command = $client->getCommand('post_command', array('test' => 'Hi!', 'test_2' => 'There', 'test_3' => __FILE__));
$request = $command->prepare();
$this->assertEquals('Hi!', $request->getPostField('test'));
$this->assertEquals('There', $request->getPostField('foo'));
$this->assertInternalType('array', $request->getPostFile('test_3'));
$command = $client->getCommand('post_command', array('test_3' => new PostFile('baz', __FILE__)));
$request = $command->prepare();
$this->assertInternalType('array', $request->getPostFile('baz'));
}
示例9: 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);
}
示例10: testUsesRelativePaths
/**
* @covers Guzzle\Service\Command\DynamicCommand::build
*/
public function testUsesRelativePaths()
{
$service = new ServiceDescription(array('test_path' => new ApiCommand(array('method' => 'GET', 'path' => 'test/abc'))));
$client = new Client('http://www.test.com/api/v2');
$client->setDescription($service);
$command = $client->getCommand('test_path');
$request = $command->prepare();
$this->assertEquals('/api/v2/test/abc', $request->getPath());
}
示例11: getCommand
public function getCommand($name, array $args = array())
{
$default_headers = array('content-type' => 'application/json', 'accept' => 'application/json');
$args['headers'] = array_merge($default_headers, isset($args['headers']) ? $args['headers'] : array());
return parent::getCommand($name, $args);
}
示例12: testAllowsCustomVisitor
/**
* @covers Guzzle\Service\Command\DynamicCommand::addVisitor
*/
public function testAllowsCustomVisitor()
{
$service = new ServiceDescription(array('foo' => new ApiCommand(array('params' => array('test' => array('location' => 'query'))))));
$client = new Client();
$client->setDescription($service);
$command = $client->getCommand('foo', array('test' => 'hi'));
// Flip query and header
$command->addVisitor('query', new HeaderVisitor());
$request = $command->prepare();
$this->assertEquals('hi', (string) $request->getHeader('test'));
}
示例13: api
/**
* Call Api
*
* @param string $command
* @param array $parameters
* @return array
*/
public function api($command, $parameters = [])
{
$command = $this->client->getCommand($command, $parameters);
return $command->execute();
}