Lines
0.00%
0 / 8
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| TopicPublisher | 0.00% | 0 / 8 | 0.00% | 0 / 2 | 6 | 0.00% | 0 / 1 | |||
| __construct | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| publish | 0.00% | 0 / 7 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Worker\Context; | |
| 6 | ||
| 7 | use Stewart\Contracts\Time\Clock; | |
| 8 | use Stewart\Runtime\Exception\TransportException; | |
| 9 | use Stewart\Runtime\Ipc\Message\Publish; | |
| 10 | use Stewart\Runtime\Ipc\Transport; | |
| 11 | use Stewart\Runtime\Model\ResourceScope; | |
| 12 | use Stewart\Runtime\Worker\AppActivityCounters; | |
| 13 | use Stewart\Support\Wire\TopicPayload; | |
| 14 | ||
| 15 | final readonly class TopicPublisher | |
| 16 | { | |
| 17 | public function __construct( | |
| 18 | private Transport $transport, | |
| 19 | private Clock $clock, | |
| 20 | private AppActivityCounters $activityCounters, | |
| 21 | ) {} | |
| 22 | ||
| 23 | /** @throws TransportException */ | |
| 24 | public function publish(ResourceScope $scope, string $topic, TopicPayload $payload): void | |
| 25 | { | |
| 26 | $this->transport->send(new Publish( | |
| 27 | topic: $topic, | |
| 28 | payload: $payload->value, | |
| 29 | publisherScope: $scope, | |
| 30 | publishedAt: $this->clock->getNow(), | |
| 31 | )); | |
| 32 | $this->activityCounters->findOrCreateActivityForScope($scope)->recordPublish(); | |
| 33 | } | |
| 34 | } |