1: <?php
2:
3: namespace Guzzle\Service\Command\Factory;
4:
5: use Guzzle\Inflection\InflectorInterface;
6: use Guzzle\Inflection\Inflector;
7: use Guzzle\Service\ClientInterface;
8:
9: 10: 11:
12: class ConcreteClassFactory implements FactoryInterface
13: {
14: 15: 16:
17: protected $client;
18:
19: 20: 21:
22: protected $inflector;
23:
24: 25: 26: 27:
28: public function __construct(ClientInterface $client, InflectorInterface $inflector = null)
29: {
30: $this->client = $client;
31: $this->inflector = $inflector ?: Inflector::getDefault();
32: }
33:
34: 35: 36:
37: public function factory($name, array $args = array())
38: {
39:
40: $prefix = $this->client->getConfig('command.prefix');
41: if (!$prefix) {
42:
43: $prefix = implode('\\', array_slice(explode('\\', get_class($this->client)), 0, -1)) . '\\Command\\';
44: $this->client->getConfig()->set('command.prefix', $prefix);
45: }
46:
47: $class = $prefix . str_replace(' ', '\\', ucwords(str_replace('.', ' ', $this->inflector->camel($name))));
48:
49:
50: if (class_exists($class)) {
51: return new $class($args);
52: }
53: }
54: }
55: