Completed
Push — master ( c6635f...c8eea5 )
by Claude
03:23
created

PrefixedExchangesClient::getExchange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Puzzle\AMQP\Clients\Decorators;
4
5
use Puzzle\AMQP\Client;
6
use Puzzle\AMQP\WritableMessage;
7
use Psr\Log\LoggerAwareTrait;
8
9
class PrefixedExchangesClient implements Client
10
{
11
    const
12
        DELIMITER = '.';
13
    
14
    use LoggerAwareTrait;
15
    
16
    private
17
        $client,
18
        $exchangesPrefix;
19
    
20
    public function __construct(Client $client, $exchangesPrefix)
21
    {
22
        $this->client = $client;
23
        $this->exchangesPrefix = $exchangesPrefix;
24
    }
25
    
26
    public function publish($exchangeName, WritableMessage $message)
27
    {
28
        return $this->client->publish(
29
            $this->computeExchangeName($exchangeName),
30
            $message
31
        );
32
    }
33
    
34
    private function computeExchangeName($exchangeName)
35
    {
36
        $exchangeParts = [];
37
        
38
        if(! empty($this->exchangesPrefix))
39
        {
40
            $exchangeParts[] = trim($this->exchangesPrefix);
41
        }
42
43
        $exchangeParts[] = $exchangeName;
44
        
45
        return trim(implode(self::DELIMITER, $exchangeParts));
46
            
47
    }
48
    
49
    public function getQueue($queueName)
50
    {
51
        return $this->client->getQueue($queueName);
52
    }
53
    
54
    public function getExchange($exchangeName)
55
    {
56
        return $this->client->getExchange(
57
            $this->computeExchangeName($exchangeName)
58
        );
59
    }
60
}
61