CamelCase). */ class WaiterClassFactory implements WaiterFactoryInterface { /** * @var array List of namespaces used to look for classes */ protected $namespaces; /** * @var InflectorInterface Inflector used to inflect class names */ protected $inflector; /** * @param array|string $namespaces Namespaces of waiter objects * @param InflectorInterface $inflector Inflector used to resolve class names */ public function __construct($namespaces = array(), InflectorInterface $inflector = null) { $this->namespaces = (array) $namespaces; $this->inflector = $inflector ?: Inflector::getDefault(); } /** * Registers a namespace to check for Waiters * * @param string $namespace Namespace which contains Waiter classes * * @return self */ public function registerNamespace($namespace) { array_unshift($this->namespaces, $namespace); return $this; } /** * {@inheritdoc} */ public function build($waiter) { if (!($className = $this->getClassName($waiter))) { throw new InvalidArgumentException("Waiter was not found matching {$waiter}."); } return new $className(); } /** * {@inheritdoc} */ public function canBuild($waiter) { return $this->getClassName($waiter) !== null; } /** * Get the name of a waiter class * * @param string $waiter Waiter name * * @return string|null */ protected function getClassName($waiter) { $waiterName = $this->inflector->camel($waiter); // Determine the name of the class to load $className = null; foreach ($this->namespaces as $namespace) { $potentialClassName = $namespace . '\\' . $waiterName; if (class_exists($potentialClassName)) { return $potentialClassName; } } return null; } }