mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 02:22:57 +01:00
Setting a service description no longer messes with command factories
Adding some missing inheritdoc docblocks
This commit is contained in:
parent
ff6738a028
commit
31a1a522fa
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user