-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectorService.php
40 lines (33 loc) · 1.15 KB
/
ProjectorService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
use Google\Protobuf\Internal\Message;
use Projection\ProjectionRequest;
class ProjectorService extends \Projection\ProjectionStub
{
private MongoProjector $projector;
public function __construct(MongoProjector $projector)
{
$this->projector = $projector;
}
public function Project(
\Grpc\ServerCallReader $reader,
\Grpc\ServerCallWriter $writer,
\Grpc\ServerContext $context): void
{
$ignored = $this->ToAny(new Projection\Ignore());
/** @var ProjectionRequest $ctx */
while ($ctx = $reader->read()) {
$eventType = $ctx->getEventType();
print("Received " . $eventType . "\r\n");
$resp = $this->projector->Project($eventType, $ctx->getEventPayload());
$response = new Projection\ProjectionResponse();
$response->setEventId($ctx->getEventId());
$response->setOperation($this->ToAny($resp));
$writer->write($response);
}
}
function ToAny(Message $message): \Google\Protobuf\Any {
$any = new \Google\Protobuf\Any();
$any->pack($message);
return $any;
}
}