Completed
Pull Request — 0.4 (#35)
by jean
10:46
created

MessageProviderFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Darkilliant\MqProcessBundle\Message\Provider;
4
5
use PhpAmqpLib\Connection\AMQPStreamConnection;
6
use Psr\Container\ContainerInterface;
7
8
class MessageProviderFactory
9
{
10
    /** @var array */
11
    private $messageProvider = [];
12
13
    /** @var ContainerInterface */
14
    private $container;
15
16
    public function __construct(ContainerInterface $container)
17
    {
18
        $this->container = $container;
19
    }
20
21
    public function factory(string $name, array $config)
22
    {
23
        if (isset($this->messageProvider[$name])) {
24
            return $this->messageProvider[$name];
25
        }
26
27
        if ('amqp_lib' === $config['client']) {
28
            /** @var $connexion AMQPStreamConnection */
29
            $connexion = $this->container->get($config['connexion'] ?? 'darkilliant_mqprocess_connection');
30
31
            return $this->messageProvider[$name] = new AmqpMessageProvider(
32
                $connexion->channel(),
33
                $config['queue'],
34
                $config['exchange'],
35
                $config['persistant'],
36
                $config['batch_count']
37
            );
38
        }
39
40
        return null;
41
    }
42
}
43