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