11<?php
22
3- namespace Enqueue \Amqplib ;
3+ namespace Enqueue \AmqpLib ;
44
55use Interop \Queue \Exception ;
66use Interop \Queue \InvalidDestinationException ;
77use Interop \Queue \PsrContext ;
88use Interop \Queue \PsrDestination ;
99use Interop \Queue \PsrTopic ;
10+ use PhpAmqpLib \Channel \AMQPChannel ;
1011use PhpAmqpLib \Connection \AbstractConnection ;
1112
1213class AmqpContext implements PsrContext
1314{
15+ /**
16+ * @var AbstractConnection
17+ */
1418 private $ connection ;
19+
20+ /**
21+ * @var AMQPChannel
22+ */
1523 private $ channel ;
1624
25+ /**
26+ * @param AbstractConnection $connection
27+ */
1728 public function __construct (AbstractConnection $ connection )
1829 {
1930 $ this ->connection = $ connection ;
2031 }
2132
33+ /**
34+ * @param string|null $body
35+ * @param array $properties
36+ * @param array $headers
37+ *
38+ * @return AmqpMessage
39+ */
2240 public function createMessage ($ body = null , array $ properties = [], array $ headers = [])
2341 {
2442 return new AmqpMessage ($ body , $ properties , $ headers );
2543 }
2644
45+ /**
46+ * @param string $name
47+ *
48+ * @return AmqpQueue
49+ */
2750 public function createQueue ($ name )
2851 {
2952 return new AmqpQueue ($ name );
3053 }
3154
55+ /**
56+ * @param string $name
57+ *
58+ * @return AmqpTopic
59+ */
3260 public function createTopic ($ name )
3361 {
3462 return new AmqpTopic ($ name );
3563 }
3664
65+ /**
66+ * @param PsrDestination $destination
67+ *
68+ * @return AmqpConsumer
69+ */
3770 public function createConsumer (PsrDestination $ destination )
3871 {
3972 InvalidDestinationException ::assertDestinationInstanceOf ($ destination , AmqpQueue::class);
4073
4174 return new AmqpConsumer ($ this ->getChannel (), $ destination );
4275 }
4376
77+ /**
78+ * @return AmqpProducer
79+ */
4480 public function createProducer ()
4581 {
4682 return new AmqpProducer ($ this ->getChannel ());
4783 }
4884
85+ /**
86+ * @return AmqpQueue
87+ */
4988 public function createTemporaryQueue ()
5089 {
5190 $ queue = $ this ->createQueue (null );
@@ -56,6 +95,9 @@ public function createTemporaryQueue()
5695 return $ queue ;
5796 }
5897
98+ /**
99+ * @param AmqpTopic $destination
100+ */
59101 public function declareTopic (PsrDestination $ destination )
60102 {
61103 InvalidDestinationException ::assertDestinationInstanceOf ($ destination , AmqpTopic::class);
@@ -73,6 +115,9 @@ public function declareTopic(PsrDestination $destination)
73115 );
74116 }
75117
118+ /**
119+ * @param AmqpQueue $destination
120+ */
76121 public function declareQueue (PsrDestination $ destination )
77122 {
78123 InvalidDestinationException ::assertDestinationInstanceOf ($ destination , AmqpQueue::class);
@@ -89,6 +134,12 @@ public function declareQueue(PsrDestination $destination)
89134 );
90135 }
91136
137+ /**
138+ * @param AmqpTopic|AmqpQueue $source
139+ * @param AmqpTopic|AmqpQueue $target
140+ *
141+ * @throws Exception
142+ */
92143 public function bind (PsrDestination $ source , PsrDestination $ target )
93144 {
94145 $ source instanceof PsrTopic
@@ -138,16 +189,16 @@ public function bind(PsrDestination $source, PsrDestination $target)
138189 }
139190 }
140191
141- /**
142- * {@inheritdoc}
143- */
144192 public function close ()
145193 {
146194 if ($ this ->channel ) {
147195 $ this ->channel ->close ();
148196 }
149197 }
150198
199+ /**
200+ * @return AMQPChannel
201+ */
151202 private function getChannel ()
152203 {
153204 if (null === $ this ->channel ) {
0 commit comments