factories = $factories; } /** * {@inheritdoc} */ public function build($waiter) { if (!($factory = $this->getFactory($waiter))) { throw new InvalidArgumentException("Waiter was not found matching {$waiter}."); } return $factory->build($waiter); } /** * {@inheritdoc} */ public function canBuild($waiter) { return (bool) $this->getFactory($waiter); } /** * Add a factory to the composite factory * * @param WaiterFactoryInterface $factory Factory to add * * @return self */ public function addFactory(WaiterFactoryInterface $factory) { $this->factories[] = $factory; return $this; } /** * Get the factory that matches the waiter name * * @param string $waiter Name of the waiter * * @return WaiterFactoryInterface|bool */ protected function getFactory($waiter) { foreach ($this->factories as $factory) { if ($factory->canBuild($waiter)) { return $factory; } } return false; } }