From 31a1a522fa25ff5b587ca22784945beddd570833 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Fri, 22 Feb 2013 22:19:07 -0800 Subject: [PATCH] Setting a service description no longer messes with command factories Adding some missing inheritdoc docblocks --- src/Guzzle/Service/Client.php | 87 +++-------------------- src/Guzzle/Service/ClientInterface.php | 13 ++-- tests/Guzzle/Tests/Service/ClientTest.php | 33 --------- 3 files changed, 18 insertions(+), 115 deletions(-) diff --git a/src/Guzzle/Service/Client.php b/src/Guzzle/Service/Client.php index 1ae54850..9b0740e8 100644 --- a/src/Guzzle/Service/Client.php +++ b/src/Guzzle/Service/Client.php @@ -13,9 +13,7 @@ use Guzzle\Service\Exception\CommandTransferException; use Guzzle\Http\Message\RequestInterface; use Guzzle\Service\Command\CommandInterface; use Guzzle\Service\Command\Factory\CompositeFactory; -use Guzzle\Service\Command\Factory\ServiceDescriptionFactory; use Guzzle\Service\Command\Factory\FactoryInterface as CommandFactoryInterface; -use Guzzle\Service\Resource\ResourceIteratorInterface; use Guzzle\Service\Resource\ResourceIteratorClassFactory; use Guzzle\Service\Resource\ResourceIteratorFactoryInterface; use Guzzle\Service\Description\ServiceDescriptionInterface; @@ -110,15 +108,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Get a command by name. First, the client will see if it has a service description and if the service description - * defines a command by the supplied name. If no dynamic command is found, the client will look for a concrete - * command class exists matching the name supplied. If neither are found, an InvalidArgumentException is thrown. - * - * @param string $name Name of the command to retrieve - * @param array $args Arguments to pass to the command - * - * @return CommandInterface - * @throws InvalidArgumentException if no command can be found by name + * {@inheritdoc} */ public function getCommand($name, array $args = array()) { @@ -148,11 +138,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Set the command factory used to create commands by name - * - * @param CommandFactoryInterface $factory Command factory - * - * @return Client + * {@inheritdoc} */ public function setCommandFactory(CommandFactoryInterface $factory) { @@ -162,11 +148,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Set the resource iterator factory associated with the client - * - * @param ResourceIteratorFactoryInterface $factory Resource iterator factory - * - * @return Client + * {@inheritdoc} */ public function setResourceIteratorFactory(ResourceIteratorFactoryInterface $factory) { @@ -176,13 +158,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Get a resource iterator from the client. - * - * @param string|CommandInterface $command Command class or command name. - * @param array $commandOptions Command options used when creating commands. - * @param array $iteratorOptions Iterator options passed to the iterator when it is instantiated. - * - * @return ResourceIteratorInterface + * {@inheritdoc} */ public function getIterator($command, array $commandOptions = null, array $iteratorOptions = array()) { @@ -194,13 +170,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Execute one or more commands - * - * @param CommandInterface|array $command Command or array of commands to execute - * - * @return mixed Returns the result of the executed command or an array of commands if executing multiple commands - * @throws InvalidArgumentException if an invalid command is passed - * @throws CommandTransferException if an exception is encountered when transferring multiple commands + * {@inheritdoc} */ public function execute($command) { @@ -263,37 +233,12 @@ class Client extends HttpClient implements ClientInterface } /** - * Set the service description of the client - * - * @param ServiceDescriptionInterface $service Service description - * @param bool $updateFactory Set to false to not update the service description based - * command factory if it is not already on the client. - * @return Client + * {@inheritdoc} */ - public function setDescription(ServiceDescriptionInterface $service, $updateFactory = true) + public function setDescription(ServiceDescriptionInterface $service) { $this->serviceDescription = $service; - // Add the service description factory to the factory chain if it is not set - if ($updateFactory) { - // Convert non chain factories to a chain factory - if (!($this->getCommandFactory() instanceof CompositeFactory)) { - $this->commandFactory = new CompositeFactory(array($this->commandFactory)); - } - // Add a service description factory if one does not already exist - if (!$this->commandFactory->has('Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory')) { - // Add the service description factory before the concrete factory - $this->commandFactory->add( - new ServiceDescriptionFactory($service), - 'Guzzle\\Service\\Command\\Factory\\ConcreteClassFactory' - ); - } else { - // Update an existing service description factory - $factory = $this->commandFactory->find('Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory'); - $factory->setServiceDescription($service); - } - } - // If a baseUrl was set on the description, then update the client if ($baseUrl = $service->getBaseUrl()) { $this->setBaseUrl($baseUrl); @@ -303,9 +248,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Get the service description of the client - * - * @return ServiceDescriptionInterface|null + * {@inheritdoc} */ public function getDescription() { @@ -313,11 +256,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Set the inflector used with the client - * - * @param InflectorInterface $inflector Inflection object - * - * @return Client + * {@inheritdoc} */ public function setInflector(InflectorInterface $inflector) { @@ -327,9 +266,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Get the inflector used with the client - * - * @return InflectorInterface + * {@inheritdoc} */ public function getInflector() { @@ -341,9 +278,7 @@ class Client extends HttpClient implements ClientInterface } /** - * Get the resource iterator factory associated with the client - * - * @return ResourceIteratorFactoryInterface + * {@inheritdoc} */ protected function getResourceIteratorFactory() { diff --git a/src/Guzzle/Service/ClientInterface.php b/src/Guzzle/Service/ClientInterface.php index 68963470..a1c3795a 100644 --- a/src/Guzzle/Service/ClientInterface.php +++ b/src/Guzzle/Service/ClientInterface.php @@ -6,6 +6,7 @@ use Guzzle\Common\FromConfigInterface; use Guzzle\Common\Exception\InvalidArgumentException; use Guzzle\Inflection\InflectorInterface; use Guzzle\Http\ClientInterface as HttpClientInterface; +use Guzzle\Service\Exception\CommandTransferException; use Guzzle\Service\Command\CommandInterface; use Guzzle\Service\Description\ServiceDescriptionInterface; use Guzzle\Service\Command\Factory\FactoryInterface as CommandFactoryInterface; @@ -18,8 +19,8 @@ use Guzzle\Service\Resource\ResourceIteratorFactoryInterface; interface ClientInterface extends HttpClientInterface, FromConfigInterface { /** - * Get a command by name. First, the client will see if it has a service description and if the service description - * defines a command by the supplied name. If no dynamic command is found, the client will look for a concrete + * Get a command by name. First, the client will see if it has a service description and if the service description + * defines a command by the supplied name. If no dynamic command is found, the client will look for a concrete * command class exists matching the name supplied. If neither are found, an InvalidArgumentException is thrown. * * @param string $name Name of the command to retrieve @@ -37,18 +38,18 @@ interface ClientInterface extends HttpClientInterface, FromConfigInterface * * @return mixed Returns the result of the executed command or an array of commands if executing multiple commands * @throws InvalidArgumentException if an invalid command is passed + * @throws CommandTransferException if an exception is encountered when transferring multiple commands */ public function execute($command); /** * Set the service description of the client * - * @param ServiceDescriptionInterface $service Service description - * @param bool $updateFactory Set to false to not update the service description based - * command factory if it is not already on the client. + * @param ServiceDescriptionInterface $service Service description + * * @return ClientInterface */ - public function setDescription(ServiceDescriptionInterface $service, $updateFactory = true); + public function setDescription(ServiceDescriptionInterface $service); /** * Get the service description of the client diff --git a/tests/Guzzle/Tests/Service/ClientTest.php b/tests/Guzzle/Tests/Service/ClientTest.php index 3b70981b..41900f3f 100644 --- a/tests/Guzzle/Tests/Service/ClientTest.php +++ b/tests/Guzzle/Tests/Service/ClientTest.php @@ -184,39 +184,6 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase $this->assertSame($description, $client->getDescription()); } - /** - * @covers Guzzle\Service\Client::setDescription - */ - public function testSettingServiceDescriptionUpdatesFactories() - { - $client = new Mock\MockClient(); - $factory = $this->getMockBuilder('Guzzle\\Service\\Command\\Factory\\MapFactory') - ->disableOriginalConstructor() - ->getMock(); - $client->setCommandFactory($factory); - - $description = $this->getMock('Guzzle\\Service\\Description\\ServiceDescription'); - $client->setDescription($description); - - $cf = $this->readAttribute($client, 'commandFactory'); - $this->assertNotSame($factory, $cf); - $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\CompositeFactory', $cf); - - $array = $cf->getIterator()->getArrayCopy(); - $this->assertSame($array[0], $factory); - $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory', $array[1]); - $this->assertSame($description, $array[1]->getServiceDescription()); - - $description2 = $this->getMock('Guzzle\\Service\\Description\\ServiceDescription'); - $client->setDescription($description2); - - $cf = $this->readAttribute($client, 'commandFactory'); - $array = $cf->getIterator()->getArrayCopy(); - $this->assertSame($array[0], $factory); - $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory', $array[1]); - $this->assertSame($description2, $array[1]->getServiceDescription()); - } - /** * @covers Guzzle\Service\Client::__call * @expectedException BadMethodCallException