mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-16 05:44:37 +01:00
Syncing up the command interface and abstract command class. Removing extraneous methods. Coding standards updates.
This commit is contained in:
parent
8cd23cefb1
commit
6ef91c5e13
@ -52,6 +52,7 @@ abstract class AbstractCommand extends Collection implements CommandInterface
|
|||||||
*
|
*
|
||||||
* @param array|Collection $parameters (optional) Collection of parameters
|
* @param array|Collection $parameters (optional) Collection of parameters
|
||||||
* to set on the command
|
* to set on the command
|
||||||
|
* @param ApiCommand $apiCommand (optional) Command definition from description
|
||||||
*/
|
*/
|
||||||
public function __construct($parameters = null, ApiCommand $apiCommand = null)
|
public function __construct($parameters = null, ApiCommand $apiCommand = null)
|
||||||
{
|
{
|
||||||
@ -83,20 +84,6 @@ abstract class AbstractCommand extends Collection implements CommandInterface
|
|||||||
return $this->apiCommand ?: new NullObject();
|
return $this->apiCommand ?: new NullObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the API command associated with the command
|
|
||||||
*
|
|
||||||
* @param ApiCommand $apiCommand API command information
|
|
||||||
*
|
|
||||||
* @return AbstractCommand
|
|
||||||
*/
|
|
||||||
public function setApiCommand(ApiCommand $apiCommand)
|
|
||||||
{
|
|
||||||
$this->apiCommand = $apiCommand;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether or not the command can be batched
|
* Get whether or not the command can be batched
|
||||||
*
|
*
|
||||||
@ -263,28 +250,14 @@ abstract class AbstractCommand extends Collection implements CommandInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an HTTP header on the outbound request
|
* Get the object that manages the request headers that will be set on any
|
||||||
*
|
* outbound requests from the command
|
||||||
* @param string $header The name of the header to set
|
|
||||||
* @param string $value The value to set on the header
|
|
||||||
*
|
|
||||||
* @return AbstractCommand
|
|
||||||
*/
|
|
||||||
public function setRequestHeader($header, $value)
|
|
||||||
{
|
|
||||||
$this->get('headers')->set($header, $value);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the object that manages the request headers
|
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getRequestHeaders()
|
public function getRequestHeaders()
|
||||||
{
|
{
|
||||||
return ($this->request) ? $this->request->getHeaders() : $this->get('headers');
|
return $this->get('headers', new Collection());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,7 @@ use Guzzle\Common\Collection;
|
|||||||
use Guzzle\Http\Message\Response;
|
use Guzzle\Http\Message\Response;
|
||||||
use Guzzle\Http\Message\RequestInterface;
|
use Guzzle\Http\Message\RequestInterface;
|
||||||
use Guzzle\Service\Client;
|
use Guzzle\Service\Client;
|
||||||
|
use Guzzle\Service\Description\ApiCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command object to handle preparing and processing client requests and
|
* Command object to handle preparing and processing client requests and
|
||||||
@ -24,8 +25,16 @@ interface CommandInterface
|
|||||||
*
|
*
|
||||||
* @param array|Collection $parameters (optional) Collection of parameters
|
* @param array|Collection $parameters (optional) Collection of parameters
|
||||||
* to set on the command
|
* to set on the command
|
||||||
|
* @param ApiCommand $apiCommand (optional) Command definition from description
|
||||||
*/
|
*/
|
||||||
public function __construct($parameters = null);
|
public function __construct($parameters = null, ApiCommand $apiCommand = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the API command information about the command
|
||||||
|
*
|
||||||
|
* @return ApiCommand|NullObject
|
||||||
|
*/
|
||||||
|
public function getApiCommand();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether or not the command can be batched
|
* Get whether or not the command can be batched
|
||||||
@ -49,6 +58,15 @@ interface CommandInterface
|
|||||||
*/
|
*/
|
||||||
public function getClient();
|
public function getClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the client objec that will execute the command
|
||||||
|
*
|
||||||
|
* @param Client $client The client objec that will execute the command
|
||||||
|
*
|
||||||
|
* @return Command
|
||||||
|
*/
|
||||||
|
public function setClient(Client $client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the request object associated with the command
|
* Get the request object associated with the command
|
||||||
*
|
*
|
||||||
@ -95,33 +113,15 @@ interface CommandInterface
|
|||||||
*
|
*
|
||||||
* @param Client $client (optional) The client object used to execute the command
|
* @param Client $client (optional) The client object used to execute the command
|
||||||
*
|
*
|
||||||
* @return Command Provides a fluent interface.
|
* @return RequestInterface Returns the generated request
|
||||||
* @throws RuntimeException if a client object has not been set previously
|
* @throws RuntimeException if a client object has not been set previously
|
||||||
* or in the prepare()
|
* or in the prepare()
|
||||||
*/
|
*/
|
||||||
public function prepare(Client $client = null);
|
public function prepare(Client $client = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the client objec that will execute the command
|
* Get the object that manages the request headers that will be set on any
|
||||||
*
|
* outbound requests from the command
|
||||||
* @param Client $client The client objec that will execute the command
|
|
||||||
*
|
|
||||||
* @return Command
|
|
||||||
*/
|
|
||||||
public function setClient(Client $client);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set an HTTP header on the outbound request
|
|
||||||
*
|
|
||||||
* @param string $header The name of the header to set
|
|
||||||
* @param string $value The value to set on the header
|
|
||||||
*
|
|
||||||
* @return AbstractCommand
|
|
||||||
*/
|
|
||||||
public function setRequestHeader($header, $value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the object that manages the request headers
|
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -44,7 +44,7 @@ class CommandSet implements \IteratorAggregate, \Countable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pool = (!$pool) ? new Pool() : $pool;
|
$this->pool = $pool ?: new Pool();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,8 +168,8 @@ class CommandSet implements \IteratorAggregate, \Countable
|
|||||||
*/
|
*/
|
||||||
public function hasCommand($command)
|
public function hasCommand($command)
|
||||||
{
|
{
|
||||||
return (bool)(count(array_filter($this->commands, function($value) use ($command) {
|
return (bool) (count(array_filter($this->commands, function($value) use ($command) {
|
||||||
return (is_string($command)) ? ($value instanceof $command) : ($value === $command);
|
return is_string($command) ? ($value instanceof $command) : ($value === $command);
|
||||||
})) > 0);
|
})) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ class CommandSet implements \IteratorAggregate, \Countable
|
|||||||
public function removeCommand($command)
|
public function removeCommand($command)
|
||||||
{
|
{
|
||||||
$this->commands = array_values(array_filter($this->commands, function($value) use ($command) {
|
$this->commands = array_values(array_filter($this->commands, function($value) use ($command) {
|
||||||
return (is_string($command)) ? (!($value instanceof $command)) : ($value !== $command);
|
return is_string($command) ? !($value instanceof $command) : ($value !== $command);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -29,6 +29,7 @@ class DynamicCommandFactory implements CommandFactoryInterface
|
|||||||
{
|
{
|
||||||
if ($command->getConcreteClass() != 'Guzzle\\Service\\Command\\ClosureCommand') {
|
if ($command->getConcreteClass() != 'Guzzle\\Service\\Command\\ClosureCommand') {
|
||||||
$class = $command->getConcreteClass();
|
$class = $command->getConcreteClass();
|
||||||
|
|
||||||
return new $class($args);
|
return new $class($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ class XmlDescriptionBuilder implements DescriptionBuilderInterface
|
|||||||
'doc' => (string) $command->doc,
|
'doc' => (string) $command->doc,
|
||||||
'method' => (string) $attr->method,
|
'method' => (string) $attr->method,
|
||||||
'path' => (string) $attr->path,
|
'path' => (string) $attr->path,
|
||||||
'min_args' => (int)(string) $attr->min_args,
|
'min_args' => (int) (string) $attr->min_args,
|
||||||
'can_batch' => (string) $attr->can_batch == 'false' ? false : true,
|
'can_batch' => (string) $attr->can_batch == 'false' ? false : true,
|
||||||
'class' => (string) $attr->class ?: ServiceDescription::DEFAULT_COMMAND_CLASS,
|
'class' => (string) $attr->class ?: ServiceDescription::DEFAULT_COMMAND_CLASS,
|
||||||
'args' => $args
|
'args' => $args
|
||||||
|
@ -95,10 +95,10 @@ abstract class ResourceIterator extends AbstractSubject implements \Iterator, \C
|
|||||||
{
|
{
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->limit = (array_key_exists('limit', $data)) ? $data['limit'] : -1;
|
$this->limit = array_key_exists('limit', $data) ? $data['limit'] : -1;
|
||||||
$this->pageSize = (array_key_exists('page_size', $data)) ? $data['page_size'] : false;
|
$this->pageSize = array_key_exists('page_size', $data) ? $data['page_size'] : false;
|
||||||
$this->resourceList = (array_key_exists('resources', $data)) ? $data['resources'] : array();
|
$this->resourceList = array_key_exists('resources', $data) ? $data['resources'] : array();
|
||||||
$this->nextToken = (array_key_exists('next_token', $data)) ? $data['next_token'] : false;
|
$this->nextToken = array_key_exists('next_token', $data) ? $data['next_token'] : false;
|
||||||
$this->retrievedCount = count($this->resourceList);
|
$this->retrievedCount = count($this->resourceList);
|
||||||
$this->onLoad();
|
$this->onLoad();
|
||||||
}
|
}
|
||||||
|
@ -174,13 +174,12 @@ class CommandTest extends AbstractCommandTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Guzzle\Service\Command\AbstractCommand::prepare
|
* @covers Guzzle\Service\Command\AbstractCommand::prepare
|
||||||
* @covers Guzzle\Service\Command\AbstractCommand::setRequestHeader
|
|
||||||
* @covers Guzzle\Service\Command\AbstractCommand::getRequestHeaders
|
* @covers Guzzle\Service\Command\AbstractCommand::getRequestHeaders
|
||||||
*/
|
*/
|
||||||
public function testCommandsAllowsCustomRequestHeaders()
|
public function testCommandsAllowsCustomRequestHeaders()
|
||||||
{
|
{
|
||||||
$command = new MockCommand();
|
$command = new MockCommand();
|
||||||
$command->setRequestHeader('test', '123');
|
$command->getRequestHeaders()->set('test', '123');
|
||||||
$this->assertInstanceOf('Guzzle\Common\Collection', $command->getRequestHeaders());
|
$this->assertInstanceOf('Guzzle\Common\Collection', $command->getRequestHeaders());
|
||||||
$this->assertEquals('123', $command->getRequestHeaders()->get('test'));
|
$this->assertEquals('123', $command->getRequestHeaders()->get('test'));
|
||||||
|
|
||||||
@ -213,8 +212,6 @@ class CommandTest extends AbstractCommandTest
|
|||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
$command->prepare($client);
|
$command->prepare($client);
|
||||||
$this->assertEquals('123', $command->get('test'));
|
$this->assertEquals('123', $command->get('test'));
|
||||||
|
|
||||||
$this->assertSame($command, $command->setApiCommand($api));
|
|
||||||
$this->assertSame($api, $command->getApiCommand($api));
|
$this->assertSame($api, $command->getApiCommand($api));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user