1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TreeHouse\Queue\Amqp\Driver\Amqp; |
4
|
|
|
|
5
|
|
|
use TreeHouse\Queue\Amqp\ChannelInterface; |
6
|
|
|
use TreeHouse\Queue\Amqp\ConnectionInterface; |
7
|
|
|
use TreeHouse\Queue\Exception\ChannelException; |
8
|
|
|
use TreeHouse\Queue\Exception\ConnectionException; |
9
|
|
|
|
10
|
|
|
class Channel implements ChannelInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \AMQPChannel |
14
|
|
|
*/ |
15
|
|
|
protected $delegate; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ConnectionInterface |
19
|
|
|
*/ |
20
|
|
|
protected $connection; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \AMQPChannel $delegate |
24
|
|
|
* @param ConnectionInterface $connection |
25
|
|
|
*/ |
26
|
27 |
|
public function __construct(\AMQPChannel $delegate, ConnectionInterface &$connection) |
27
|
|
|
{ |
28
|
27 |
|
$this->delegate = $delegate; |
29
|
27 |
|
$this->connection = &$connection; |
30
|
27 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
3 |
|
public function getConnection() |
36
|
|
|
{ |
37
|
3 |
|
return $this->connection; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
1 |
|
public function getChannelId() |
44
|
|
|
{ |
45
|
1 |
|
return $this->delegate->getChannelId(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritdoc |
50
|
|
|
*/ |
51
|
2 |
View Code Duplication |
public function basicQos($prefetchSize, $prefetchCount) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
try { |
54
|
2 |
|
return $this->delegate->qos($prefetchSize, $prefetchCount); |
55
|
1 |
|
} catch (\AMQPChannelException $e) { |
56
|
|
|
throw new ChannelException($e->getMessage(), $e->getCode(), $e); |
57
|
1 |
|
} catch (\AMQPConnectionException $e) { |
58
|
1 |
|
throw new ConnectionException($e->getMessage(), $e->getCode(), $e); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
65
|
3 |
View Code Duplication |
public function startTransaction() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
try { |
68
|
3 |
|
return $this->delegate->startTransaction(); |
69
|
1 |
|
} catch (\AMQPChannelException $e) { |
70
|
1 |
|
throw new ChannelException($e->getMessage(), $e->getCode(), $e); |
71
|
|
|
} catch (\AMQPConnectionException $e) { |
72
|
|
|
throw new ConnectionException($e->getMessage(), $e->getCode(), $e); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
3 |
View Code Duplication |
public function commitTransaction() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
try { |
82
|
3 |
|
return $this->delegate->commitTransaction(); |
83
|
2 |
|
} catch (\AMQPChannelException $e) { |
84
|
2 |
|
throw new ChannelException($e->getMessage(), $e->getCode(), $e); |
85
|
|
|
} catch (\AMQPConnectionException $e) { |
86
|
|
|
throw new ConnectionException($e->getMessage(), $e->getCode(), $e); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @inheritdoc |
92
|
|
|
*/ |
93
|
2 |
View Code Duplication |
public function rollbackTransaction() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
try { |
96
|
2 |
|
return $this->delegate->rollbackTransaction(); |
97
|
2 |
|
} catch (\AMQPChannelException $e) { |
98
|
2 |
|
throw new ChannelException($e->getMessage(), $e->getCode(), $e); |
99
|
|
|
} catch (\AMQPConnectionException $e) { |
100
|
|
|
throw new ConnectionException($e->getMessage(), $e->getCode(), $e); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @inheritdoc |
106
|
|
|
* |
107
|
|
|
* @return \AMQPChannel |
108
|
|
|
*/ |
109
|
14 |
|
public function getDelegate() |
110
|
|
|
{ |
111
|
14 |
|
return $this->delegate; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.