/**
  * @param ContainerInterface $container
  * @return Connection
  */
 public function __invoke(ContainerInterface $container) : Connection
 {
     if (!$container->has(Driver::class)) {
         throw new Exception\RuntimeException('No driver factory registered in container');
     }
     $options = $this->options($container->get('config'), $this->connectionName);
     switch ($container->get(Driver::class)) {
         case Driver::AMQP_EXTENSION():
             $connection = new \Humus\Amqp\Driver\AmqpExtension\Connection($options);
             $connection->connect();
             break;
         case Driver::PHP_AMQP_LIB():
         default:
             if (!isset($options['type'])) {
                 throw new Exception\InvalidArgumentException('For php-amqplib driver a connection type is required');
             }
             $type = $options['type'];
             unset($options['type']);
             switch ($type) {
                 case 'lazy':
                 case LazyConnection::class:
                     $connection = new LazyConnection($options);
                     break;
                 case 'lazy_socket':
                 case LazySocketConnection::class:
                     $connection = new LazySocketConnection($options);
                     break;
                 case 'socket':
                 case SocketConnection::class:
                     $connection = new SocketConnection($options);
                     break;
                 case 'ssl':
                 case SslConnection::class:
                     return new SslConnection($options);
                 case 'stream':
                 case StreamConnection::class:
                     $connection = new StreamConnection($options);
                     break;
                 default:
                     throw new Exception\InvalidArgumentException('Invalid connection type for php-amqplib driver given');
             }
             break;
     }
     return $connection;
 }
Exemple #2
0
 /**
  * @param ContainerInterface $container
  * @return Driver
  */
 public function __invoke(ContainerInterface $container) : Driver
 {
     $options = $this->options($container->get('config'));
     return Driver::get($options['driver']);
 }