1: <?php
2:
3: /*
4: * Library to use PortBilling events with PSR-14 event dispatch
5: *
6: * Example of Event handler
7: */
8:
9: namespace Porta\Psr14Event\Example;
10:
11: use Porta\Psr14Event\Event;
12: use Porta\Psr14Event\EventHandlerBase;
13:
14: /**
15: * Example to handle two event types
16: *
17: * Handle two event types:
18: * - Account/BalanceChanged
19: * - Customer/BalanceChanged
20: *
21: * Do nothing, but writing balance changes into php main log
22: *
23: */
24: class BalanceChangeHandler extends EventHandlerBase
25: {
26:
27: protected function eventAccountBalanceChanged(Event $event): void
28: {
29: // Use event variables as array members
30: error_log("Account # {$event['billing_entity_id']} balance changed "
31: . "from {$event['prev_balance']} to {$event['curr_balance']}");
32:
33: // Register processing was successfull
34: $event->onSuccess();
35: }
36:
37: protected function eventCustomerBalanceChanged(Event $event): void
38: {
39: // Use event variables as class properties
40: error_log("Customer # $event->billing_entity_id balance changed "
41: . "from $event->prev_balance to $event->curr_balance");
42:
43: // Register processing was successfull
44: $event->onSuccess();
45: }
46: }
47: