Open Journal Systems  3.3.0
ConcreteClassFactory.php
1 <?php
2 
4 
8 
13 {
15  protected $client;
16 
18  protected $inflector;
19 
25  {
26  $this->client = $client;
27  $this->inflector = $inflector ?: Inflector::getDefault();
28  }
29 
30  public function factory($name, array $args = array())
31  {
32  // Determine the class to instantiate based on the namespace of the current client and the default directory
33  $prefix = $this->client->getConfig('command.prefix');
34  if (!$prefix) {
35  // The prefix can be specified in a factory method and is cached
36  $prefix = implode('\\', array_slice(explode('\\', get_class($this->client)), 0, -1)) . '\\Command\\';
37  $this->client->getConfig()->set('command.prefix', $prefix);
38  }
39 
40  $class = $prefix . str_replace(' ', '\\', ucwords(str_replace('.', ' ', $this->inflector->camel($name))));
41 
42  // Create the concrete command if it exists
43  if (class_exists($class)) {
44  return new $class($args);
45  }
46  }
47 }
Guzzle\Inflection\Inflector\getDefault
static getDefault()
Definition: Inflector.php:18
Guzzle\Inflection\InflectorInterface
Definition: InflectorInterface.php:8
Guzzle\Service\Command\Factory\ConcreteClassFactory
Definition: ConcreteClassFactory.php:12
Guzzle\Service\Command\Factory
Definition: AliasFactory.php:3
Guzzle\Service\Command\Factory\ConcreteClassFactory\$client
$client
Definition: ConcreteClassFactory.php:18
Guzzle\Service\ClientInterface
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Service/ClientInterface.php:16
Guzzle\Service\Command\Factory\ConcreteClassFactory\$inflector
$inflector
Definition: ConcreteClassFactory.php:24
Guzzle\Inflection\Inflector
Definition: Inflector.php:8
Guzzle\Service\Command\Factory\FactoryInterface
Definition: FactoryInterface.php:10
Guzzle\Service\Command\Factory\ConcreteClassFactory\factory
factory($name, array $args=array())
Definition: ConcreteClassFactory.php:36
Guzzle\Service\Command\Factory\ConcreteClassFactory\__construct
__construct(ClientInterface $client, InflectorInterface $inflector=null)
Definition: ConcreteClassFactory.php:30