88
99final class Rejection implements RejectionInterface
1010{
11- private Client $ connection ;
1211 private Channel $ channel ;
1312
1413 public function __construct (
15- string $ host ,
16- string $ vhost ,
14+ Client $ connection ,
15+ private string $ stepUuid ,
1716 private string $ topic ,
18- ?string $ user = 'guest ' ,
19- ?string $ password = 'guest ' ,
2017 private ?string $ exchange = null ,
21- ?int $ port = null ,
2218 ) {
23- $ this ->connection = new Client ([
19+ $ this ->channel = $ connection ->channel ();
20+ $ this ->channel ->queueDeclare (
21+ queue: $ this ->topic ,
22+ passive: false ,
23+ durable: true ,
24+ exclusive: false ,
25+ autoDelete: true ,
26+ );
27+ }
28+
29+ public static function withoutAuthentication (
30+ string $ stepUuid ,
31+ string $ host ,
32+ string $ vhost ,
33+ string $ topic ,
34+ ?string $ exchange = null ,
35+ ?int $ port = null ,
36+ ): self {
37+ $ connection = new Client ([
2438 'host ' => $ host ,
2539 'port ' => $ port ,
2640 'vhost ' => $ vhost ,
27- 'user ' => $ user ,
28- 'password ' => $ password ,
41+ 'user ' => ' guest ' ,
42+ 'password ' => ' guest ' ,
2943 ]);
30- $ this -> connection ->connect ();
44+ $ connection ->connect ();
3145
32- $ this -> channel = $ this -> connection -> channel ( );
46+ return new self ( $ connection, stepUuid: $ stepUuid , topic: $ topic , exchange: $ exchange );
3347 }
3448
35- public static function withoutAuthentication (
49+ public static function withAuthentication (
50+ string $ stepUuid ,
3651 string $ host ,
3752 string $ vhost ,
3853 string $ topic ,
54+ ?string $ user ,
55+ ?string $ password ,
3956 ?string $ exchange = null ,
4057 ?int $ port = null ,
4158 ): self {
42- return new self (host: $ host , vhost: $ vhost , topic: $ topic , exchange: $ exchange , port: $ port );
59+ $ connection = new Client ([
60+ 'host ' => $ host ,
61+ 'port ' => $ port ,
62+ 'vhost ' => $ vhost ,
63+ 'user ' => $ user ,
64+ 'password ' => $ password ,
65+ ]);
66+ $ connection ->connect ();
67+
68+ return new self ($ connection , stepUuid: $ stepUuid , topic: $ topic , exchange: $ exchange );
4369 }
4470
4571 public function reject (object |array $ rejection , ?\Throwable $ exception = null ): void
@@ -48,6 +74,7 @@ public function reject(object|array $rejection, ?\Throwable $exception = null):
4874 \json_encode ([
4975 'item ' => $ rejection ,
5076 'exception ' => $ exception ,
77+ 'step ' => $ this ->stepUuid ,
5178 ]),
5279 [
5380 'content-type ' => 'application/json ' ,
0 commit comments