1111
1212namespace Tarantool \Queue ;
1313
14+ use Tarantool \Client \Client ;
15+
1416class Queue
1517{
1618 private $ client ;
1719 private $ tubeName ;
18- private $ prefix ;
1920
20- public function __construct (\Tarantool $ client , $ tubeName )
21+ /**
22+ * @param \Tarantool|\Tarantool\Client\Client $client
23+ * @param string $tubeName
24+ *
25+ * @throws \InvalidArgumentException
26+ */
27+ public function __construct ($ client , $ tubeName )
2128 {
29+ if ($ client instanceof Client) {
30+ $ client = new ClientAdapter ($ client );
31+ } else if (!$ client instanceof \Tarantool) {
32+ throw new \InvalidArgumentException (sprintf (
33+ '%s() expects parameter 1 to be Tarantool or Tarantool\Client\Client, %s given. ' ,
34+ __METHOD__ , is_object ($ client ) ? get_class ($ client ) : gettype ($ client )
35+ ));
36+ }
37+
2238 $ this ->client = $ client ;
2339 $ this ->tubeName = $ tubeName ;
24- $ this ->prefix = "queue.tube. $ tubeName: " ;
2540 }
2641
2742 /**
28- * @param mixed $data
29- * @param array|null $options
43+ * @param mixed $data
44+ * @param array $options
3045 *
3146 * @return Task
3247 */
33- public function put ($ data , array $ options = null )
48+ public function put ($ data , array $ options = [] )
3449 {
3550 $ args = $ options ? [$ data , $ options ] : [$ data ];
36- $ result = $ this ->client ->call ($ this ->prefix . ' put ' , $ args );
51+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : put" , $ args );
3752
3853 return Task::createFromTuple ($ result [0 ]);
3954 }
@@ -46,7 +61,7 @@ public function put($data, array $options = null)
4661 public function take ($ timeout = null )
4762 {
4863 $ args = null === $ timeout ? [] : [$ timeout ];
49- $ result = $ this ->client ->call ($ this ->prefix . ' take ' , $ args );
64+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : take" , $ args );
5065
5166 return empty ($ result [0 ]) ? null : Task::createFromTuple ($ result [0 ]);
5267 }
@@ -58,21 +73,21 @@ public function take($timeout = null)
5873 */
5974 public function ack ($ taskId )
6075 {
61- $ result = $ this ->client ->call ($ this ->prefix . ' ack ' , [$ taskId ]);
76+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : ack" , [$ taskId ]);
6277
6378 return Task::createFromTuple ($ result [0 ]);
6479 }
6580
6681 /**
67- * @param int $taskId
68- * @param array|null $options
82+ * @param int $taskId
83+ * @param array $options
6984 *
7085 * @return Task
7186 */
72- public function release ($ taskId , array $ options = null )
87+ public function release ($ taskId , array $ options = [] )
7388 {
7489 $ args = $ options ? [$ taskId , $ options ] : [$ taskId ];
75- $ result = $ this ->client ->call ($ this ->prefix . ' release ' , $ args );
90+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : release" , $ args );
7691
7792 return Task::createFromTuple ($ result [0 ]);
7893 }
@@ -84,7 +99,7 @@ public function release($taskId, array $options = null)
8499 */
85100 public function peek ($ taskId )
86101 {
87- $ result = $ this ->client ->call ($ this ->prefix . ' peek ' , [$ taskId ]);
102+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : peek" , [$ taskId ]);
88103
89104 return Task::createFromTuple ($ result [0 ]);
90105 }
@@ -96,7 +111,7 @@ public function peek($taskId)
96111 */
97112 public function bury ($ taskId )
98113 {
99- $ result = $ this ->client ->call ($ this ->prefix . ' bury ' , [$ taskId ]);
114+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : bury" , [$ taskId ]);
100115
101116 return Task::createFromTuple ($ result [0 ]);
102117 }
@@ -108,7 +123,7 @@ public function bury($taskId)
108123 */
109124 public function kick ($ count )
110125 {
111- $ result = $ this ->client ->call ($ this ->prefix . ' kick ' , [$ count ]);
126+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : kick" , [$ count ]);
112127
113128 return $ result [0 ][0 ];
114129 }
@@ -120,14 +135,14 @@ public function kick($count)
120135 */
121136 public function delete ($ taskId )
122137 {
123- $ result = $ this ->client ->call ($ this ->prefix . ' delete ' , [$ taskId ]);
138+ $ result = $ this ->client ->call (" queue.tube. $ this ->tubeName : delete" , [$ taskId ]);
124139
125140 return Task::createFromTuple ($ result [0 ]);
126141 }
127142
128143 public function truncate ()
129144 {
130- $ this ->client ->call ($ this ->prefix . ' truncate ' );
145+ $ this ->client ->call (" queue.tube. $ this ->tubeName : truncate" );
131146 }
132147
133148 /**
0 commit comments