-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingProjection.php
More file actions
40 lines (36 loc) · 1.13 KB
/
BookingProjection.php
File metadata and controls
40 lines (36 loc) · 1.13 KB
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
require dirname(__FILE__) . '/MongoProjector.php';
class BookingDocument
{
public string $_id;
public string $guestId;
public string $roomId;
public float $outstandingAmount;
}
class BookingProjection extends MongoProjector
{
public function __construct()
{
parent::__construct();
// RoomBooked inserts a new document to the collection
$this->InsertOneOn("V1.RoomBooked", function ($evt) {
$doc = new BookingDocument();
$doc->_id = $evt->bookingId;
$doc->guestId = $evt->guestId;
return $doc;
});
// PaymentRegistered updates an existing document
$this->UpdateOneOn("V1.PaymentRegistered", function ($evt) {
$filter = new BookingDocument();
$filter->_id = $evt->bookingId;
$update = new stdClass();
$doc = new BookingDocument();
$doc->outstandingAmount = $evt->amount;
$update->{'$set'} = $doc;
$result = new stdClass();
$result->filter = $filter;
$result->update = $update;
return $result;
});
}
}