diff --git a/library/Guzzle/Service/Command/AbstractCommand.php b/library/Guzzle/Service/Command/AbstractCommand.php index a36bbcb4..a036b9d4 100644 --- a/library/Guzzle/Service/Command/AbstractCommand.php +++ b/library/Guzzle/Service/Command/AbstractCommand.php @@ -52,6 +52,7 @@ abstract class AbstractCommand extends Collection implements CommandInterface * * @param array|Collection $parameters (optional) Collection of parameters * to set on the command + * @param ApiCommand $apiCommand (optional) Command definition from description */ public function __construct($parameters = null, ApiCommand $apiCommand = null) { @@ -83,20 +84,6 @@ abstract class AbstractCommand extends Collection implements CommandInterface 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 * @@ -263,28 +250,14 @@ abstract class AbstractCommand extends Collection implements CommandInterface } /** - * 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) - { - $this->get('headers')->set($header, $value); - - return $this; - } - - /** - * Get the object that manages the request headers + * Get the object that manages the request headers that will be set on any + * outbound requests from the command * * @return Collection */ public function getRequestHeaders() { - return ($this->request) ? $this->request->getHeaders() : $this->get('headers'); + return $this->get('headers', new Collection()); } /** diff --git a/library/Guzzle/Service/Command/CommandInterface.php b/library/Guzzle/Service/Command/CommandInterface.php index cfb0625f..51eab136 100644 --- a/library/Guzzle/Service/Command/CommandInterface.php +++ b/library/Guzzle/Service/Command/CommandInterface.php @@ -10,6 +10,7 @@ use Guzzle\Common\Collection; use Guzzle\Http\Message\Response; use Guzzle\Http\Message\RequestInterface; use Guzzle\Service\Client; +use Guzzle\Service\Description\ApiCommand; /** * Command object to handle preparing and processing client requests and @@ -24,8 +25,16 @@ interface CommandInterface * * @param array|Collection $parameters (optional) Collection of parameters * 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 @@ -49,6 +58,15 @@ interface CommandInterface */ 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 * @@ -95,33 +113,15 @@ interface CommandInterface * * @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 * or in the prepare() */ public function prepare(Client $client = null); /** - * 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); - - /** - * 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 + * Get the object that manages the request headers that will be set on any + * outbound requests from the command * * @return Collection */ diff --git a/library/Guzzle/Service/Command/CommandSet.php b/library/Guzzle/Service/Command/CommandSet.php index d9b74264..08f4a98d 100644 --- a/library/Guzzle/Service/Command/CommandSet.php +++ b/library/Guzzle/Service/Command/CommandSet.php @@ -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) { - return (bool)(count(array_filter($this->commands, function($value) use ($command) { - return (is_string($command)) ? ($value instanceof $command) : ($value === $command); + return (bool) (count(array_filter($this->commands, function($value) use ($command) { + return is_string($command) ? ($value instanceof $command) : ($value === $command); })) > 0); } @@ -184,7 +184,7 @@ class CommandSet implements \IteratorAggregate, \Countable public function removeCommand($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; diff --git a/library/Guzzle/Service/Description/DynamicCommandFactory.php b/library/Guzzle/Service/Description/DynamicCommandFactory.php index a63dc920..4f0dea11 100644 --- a/library/Guzzle/Service/Description/DynamicCommandFactory.php +++ b/library/Guzzle/Service/Description/DynamicCommandFactory.php @@ -29,6 +29,7 @@ class DynamicCommandFactory implements CommandFactoryInterface { if ($command->getConcreteClass() != 'Guzzle\\Service\\Command\\ClosureCommand') { $class = $command->getConcreteClass(); + return new $class($args); } diff --git a/library/Guzzle/Service/Description/XmlDescriptionBuilder.php b/library/Guzzle/Service/Description/XmlDescriptionBuilder.php index 179de2eb..b651e6fc 100644 --- a/library/Guzzle/Service/Description/XmlDescriptionBuilder.php +++ b/library/Guzzle/Service/Description/XmlDescriptionBuilder.php @@ -91,7 +91,7 @@ class XmlDescriptionBuilder implements DescriptionBuilderInterface 'doc' => (string) $command->doc, 'method' => (string) $attr->method, '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, 'class' => (string) $attr->class ?: ServiceDescription::DEFAULT_COMMAND_CLASS, 'args' => $args diff --git a/library/Guzzle/Service/ResourceIterator.php b/library/Guzzle/Service/ResourceIterator.php index 8f08c70b..7d76c778 100644 --- a/library/Guzzle/Service/ResourceIterator.php +++ b/library/Guzzle/Service/ResourceIterator.php @@ -95,10 +95,10 @@ abstract class ResourceIterator extends AbstractSubject implements \Iterator, \C { $this->client = $client; $this->data = $data; - $this->limit = (array_key_exists('limit', $data)) ? $data['limit'] : -1; - $this->pageSize = (array_key_exists('page_size', $data)) ? $data['page_size'] : false; - $this->resourceList = (array_key_exists('resources', $data)) ? $data['resources'] : array(); - $this->nextToken = (array_key_exists('next_token', $data)) ? $data['next_token'] : false; + $this->limit = array_key_exists('limit', $data) ? $data['limit'] : -1; + $this->pageSize = array_key_exists('page_size', $data) ? $data['page_size'] : false; + $this->resourceList = array_key_exists('resources', $data) ? $data['resources'] : array(); + $this->nextToken = array_key_exists('next_token', $data) ? $data['next_token'] : false; $this->retrievedCount = count($this->resourceList); $this->onLoad(); } diff --git a/tests/Guzzle/Tests/Service/Command/CommandTest.php b/tests/Guzzle/Tests/Service/Command/CommandTest.php index 52360477..7f948f82 100644 --- a/tests/Guzzle/Tests/Service/Command/CommandTest.php +++ b/tests/Guzzle/Tests/Service/Command/CommandTest.php @@ -174,13 +174,12 @@ class CommandTest extends AbstractCommandTest /** * @covers Guzzle\Service\Command\AbstractCommand::prepare - * @covers Guzzle\Service\Command\AbstractCommand::setRequestHeader * @covers Guzzle\Service\Command\AbstractCommand::getRequestHeaders */ public function testCommandsAllowsCustomRequestHeaders() { $command = new MockCommand(); - $command->setRequestHeader('test', '123'); + $command->getRequestHeaders()->set('test', '123'); $this->assertInstanceOf('Guzzle\Common\Collection', $command->getRequestHeaders()); $this->assertEquals('123', $command->getRequestHeaders()->get('test')); @@ -213,8 +212,6 @@ class CommandTest extends AbstractCommandTest $client = $this->getClient(); $command->prepare($client); $this->assertEquals('123', $command->get('test')); - - $this->assertSame($command, $command->setApiCommand($api)); $this->assertSame($api, $command->getApiCommand($api)); } } \ No newline at end of file