File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
integration-docdb-to-lambda Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ require __DIR__ .'/vendor/autoload.php ' ;
4
+
5
+ use Bref \Context \Context ;
6
+ use Bref \Event \Handler ;
7
+
8
+ class DocumentDBEventHandler implements Handler
9
+ {
10
+ public function handle ($ event , Context $ context ): string
11
+ {
12
+
13
+ $ events = $ event ['events ' ] ?? [];
14
+ foreach ($ events as $ record ) {
15
+ $ this ->logDocumentDBEvent ($ record ['event ' ]);
16
+ }
17
+ return 'OK ' ;
18
+ }
19
+
20
+ private function logDocumentDBEvent ($ event ): void
21
+ {
22
+ // Extract information from the event record
23
+
24
+ $ operationType = $ event ['operationType ' ] ?? 'Unknown ' ;
25
+ $ db = $ event ['ns ' ]['db ' ] ?? 'Unknown ' ;
26
+ $ collection = $ event ['ns ' ]['coll ' ] ?? 'Unknown ' ;
27
+ $ fullDocument = $ event ['fullDocument ' ] ?? [];
28
+
29
+ // Log the event details
30
+
31
+ echo "Operation type: $ operationType \n" ;
32
+ echo "Database: $ db \n" ;
33
+ echo "Collection: $ collection \n" ;
34
+ echo "Full document: " . json_encode ($ fullDocument , JSON_PRETTY_PRINT ) . "\n" ;
35
+ }
36
+ }
37
+ return new DocumentDBEventHandler ();
You can’t perform that action at this time.
0 commit comments