Completed
Pull Request — 0.4 (#35)
by jean
11:34
created

MessagePublisherFactory::__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
declare(strict_types=1);
4
5
namespace Darkilliant\MqProcessBundle\Message\Publisher;
6
7
use PhpAmqpLib\Connection\AMQPStreamConnection;
8
use Psr\Container\ContainerInterface;
9
10
class MessagePublisherFactory
11
{
12
    /** @var array */
13
    private $messagePublisher = [];
14
15
    /** @var ContainerInterface */
16
    private $container;
17
18
    public function __construct(ContainerInterface $container)
19
    {
20
        $this->container = $container;
21
    }
22
23
    public function factory(string $name, array $config)
24
    {
25
        if (isset($this->messagePublisher[$name])) {
26
            return $this->messagePublisher[$name];
27
        }
28
29
        if ('amqp_lib' === $config['client']) {
30
            /** @var $connexion AMQPStreamConnection */
31
            $connexion = $this->container->get($config['connexion'] ?? 'darkilliant_mqprocess_connection');
32
33
            return $this->messagePublisher[$name] = new AmqpMessagePublisher(
34
                $connexion->channel(),
35
                $config['queue'],
36
                $config['exchange'],
37
                $config['persistant']
38
            );
39
        }
40
41
        return null;
42
    }
43
}
44