File tree 4 files changed +107
-0
lines changed
4 files changed +107
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Phauthentic \CorrelationIdBundle \Messenger \Middleware ;
6
+
7
+ use Phauthentic \CorrelationIdBundle \Messenger \Stamp \CorrelationIdStamp ;
8
+ use Phauthentic \Infrastructure \Utils \CorrelationID ;
9
+ use Symfony \Component \Messenger \Envelope ;
10
+ use Symfony \Component \Messenger \Middleware \MiddlewareInterface ;
11
+ use Symfony \Component \Messenger \Middleware \StackInterface ;
12
+
13
+ /**
14
+ *
15
+ */
16
+ class CorrelationIdMiddleware implements MiddlewareInterface
17
+ {
18
+ /**
19
+ * @throws \Exception
20
+ */
21
+ public function handle (Envelope $ envelope , StackInterface $ stack ): Envelope
22
+ {
23
+ if (isset ($ envelope ->all ()[CorrelationIdStamp::class])) {
24
+ return $ stack ->next ()->handle ($ envelope , $ stack );
25
+ }
26
+
27
+ $ envelope = $ envelope ->with (
28
+ new CorrelationIdStamp (CorrelationID::toString ())
29
+ );
30
+
31
+ return $ stack ->next ()->handle ($ envelope , $ stack );
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Phauthentic \CorrelationIdBundle \Messenger \Stamp ;
6
+
7
+ use Symfony \Component \Messenger \Stamp \StampInterface ;
8
+
9
+ /**
10
+ *
11
+ */
12
+ class CorrelationIdStamp implements StampInterface
13
+ {
14
+ private string $ correlationId ;
15
+
16
+ public function __construct (string $ correlationId )
17
+ {
18
+ $ this ->correlationId = $ correlationId ;
19
+ }
20
+
21
+ public function getCorrelationId (): string
22
+ {
23
+ return $ this ->correlationId ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Phauthentic \CorrelationIdBundle \Tests \Messenger \Middleware ;
6
+
7
+ use Phauthentic \CorrelationIdBundle \Messenger \Middleware \CorrelationIdMiddleware ;
8
+ use Phauthentic \CorrelationIdBundle \Messenger \Stamp \CorrelationIdStamp ;
9
+ use PHPUnit \Framework \TestCase ;
10
+ use stdClass ;
11
+ use Symfony \Component \Messenger \Envelope ;
12
+ use Symfony \Component \Messenger \Middleware \StackMiddleware ;
13
+
14
+ /**
15
+ *
16
+ */
17
+ class CorrelationIdMiddlewareTest extends TestCase
18
+ {
19
+ public function testHandle (): void
20
+ {
21
+ $ middleware = new CorrelationIdMiddleware ();
22
+ $ envelope = new Envelope (new stdClass ());
23
+ $ stack = new StackMiddleware ();
24
+
25
+ $ envelope = $ middleware ->handle ($ envelope , $ stack );
26
+
27
+ $ this ->assertArrayHasKey (CorrelationIdStamp::class, $ envelope ->all ());
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Phauthentic \CorrelationIdBundle \Tests \Messenger \Stamp ;
6
+
7
+ use Phauthentic \CorrelationIdBundle \Messenger \Stamp \CorrelationIdStamp ;
8
+ use PHPUnit \Framework \TestCase ;
9
+
10
+ /**
11
+ *
12
+ */
13
+ class CorrelationIdStampTest extends TestCase
14
+ {
15
+ public function testGetCorrelationId (): void
16
+ {
17
+ $ stamp = new CorrelationIdStamp ('foo ' );
18
+ $ this ->assertEquals ('foo ' , $ stamp ->getCorrelationId ());
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments