/** * Instantiate a queue * * @param array|Traversable $config * @return Queue * @throws Exception\InvalidArgumentException */ public static function factory($config) { if ($config instanceof Traversable) { $config = ArrayUtils::iteratorToArray($config); } if (!is_array($config)) { throw new Exception\InvalidArgumentException('The factory needs an associative array ' . 'or a Traversable object as an argument'); } if (!isset($config['name'])) { throw new Exception\InvalidArgumentException('Missing "name"'); } /** @var $adapter \Stakhanovist\Queue\Adapter\AdapterInterface */ if ($config['adapter'] instanceof AdapterInterface) { // $config['adapter'] is already an adapter object $adapter = $config['adapter']; } else { $adapter = AdapterFactory::factory($config['adapter']); } $options = null; if (isset($config['options'])) { if (!is_array($config['options'])) { throw new Exception\InvalidArgumentException(sprintf('"%s" must be an array; "%s" given.', 'options', gettype($config['options']))); } $options = new QueueOptions($config['options']); } return new static($config['name'], $adapter, $options); }
/** * This is a generic function that creates a queue * * @param string $name - name of the queue to create * @param QueueOptions $options * @return Queue */ protected function createQueue($name, QueueOptions $options = null) { $adapter = AdapterFactory::factory(['adapter' => $this->getAdapterFullName(), 'options' => $this->getTestOptions()]); $queue = new Queue($this->createQueueName($name), $adapter, $options); if (!$adapter instanceof Adapter\NullAdapter) { $queue->ensureQueue(); } return $queue; }
/** * @param ServiceLocatorInterface $services * @param string $name * @param string $requestedName * @return \Stakhanovist\Queue\Adapter\AdapterInterface */ public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) { $config = $this->getConfig($services); $config = $config[$requestedName]; return AdapterFactory::factory($config); }
public function testFactoryAdapterInvalidArgumentOptionsIsntArray() { $this->setExpectedException(InvalidArgumentException::class); $config = new \ArrayObject(); $config['adapter'] = 'Null'; $config['options'] = 'string'; Adapter\AdapterFactory::factory($config); }