dump_events.php$0 ➔ allEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
error_reporting(E_ALL);
5
date_default_timezone_set('UTC');
6
include __DIR__ . '/../vendor/autoload.php';
7
8
use MySQLReplication\Config\ConfigBuilder;
9
use MySQLReplication\Event\DTO\EventDTO;
10
use MySQLReplication\Event\EventSubscribers;
11
use MySQLReplication\MySQLReplicationFactory;
12
13
/**
14
 * Your db configuration
15
 * @see ConfigBuilder
16
 * @link https://github.com/krowinski/php-mysql-replication/blob/master/README.md
17
 */
18
$binLogStream = new MySQLReplicationFactory(
19
    (new ConfigBuilder())
20
        ->withUser('root')
21
        ->withHost('127.0.0.1')
22
        ->withPassword('root')
23
        ->withPort(3306)
24
        ->withSlaveId(100)
25
        ->withHeartbeatPeriod(2)
26
        ->build()
27
);
28
29
/**
30
 * Register your events handler
31
 * @see EventSubscribers
32
 */
33
$binLogStream->registerSubscriber(
34
    new class() extends EventSubscribers
35
    {
36
        public function allEvents(EventDTO $event): void
37
        {
38
            // all events got __toString() implementation
39
            echo $event;
40
41
            // all events got JsonSerializable implementation
42
            //echo json_encode($event, JSON_PRETTY_PRINT);
43
44
            echo 'Memory usage ' . round(memory_get_usage() / 1048576, 2) . ' MB' . PHP_EOL;
45
        }
46
    }
47
);
48
49
// start consuming events
50
$binLogStream->run();
51