1: <?php
2:
3: namespace Guzzle\Service\Command\Factory;
4:
5: use Guzzle\Common\Exception\InvalidArgumentException;
6: use Guzzle\Service\ClientInterface;
7:
8: /**
9: * Command factory used when you need to provide aliases to commands
10: */
11: class AliasFactory implements FactoryInterface
12: {
13: /**
14: * @var array Associative array mapping command aliases to the aliased command
15: */
16: protected $aliases;
17:
18: /**
19: * @var ClientInterface Client used to retry using aliases
20: */
21: protected $client;
22:
23: /**
24: * @param ClientInterface $client Client used to retry with the alias
25: * @param array $aliases Associative array mapping aliases to the alias
26: */
27: public function __construct(ClientInterface $client, array $aliases)
28: {
29: $this->client = $client;
30: $this->aliases = $aliases;
31: }
32:
33: /**
34: * {@inheritdoc}
35: */
36: public function factory($name, array $args = array())
37: {
38: if (isset($this->aliases[$name])) {
39: try {
40: return $this->client->getCommand($this->aliases[$name], $args);
41: } catch (InvalidArgumentException $e) {
42: return null;
43: }
44: }
45: }
46: }
47: