-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBeforeModelUpdate.php
More file actions
48 lines (38 loc) · 1.19 KB
/
BeforeModelUpdate.php
File metadata and controls
48 lines (38 loc) · 1.19 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
41
42
43
44
45
46
47
48
<?php
/**
* Copyright © . All rights reserved.
* See LICENSE file for license details.
*/
#AfterModelUpdateEvent
declare(strict_types=1);
namespace OxidEsales\ExamplesModule\Tracker\Subscriber;
use OxidEsales\Eshop\Core\Model\BaseModel;
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\BeforeModelUpdateEvent;
use OxidEsales\ExamplesModule\Extension\Model\UserInterface;
use OxidEsales\ExamplesModule\Tracker\Service\TrackerServiceInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @extendable-class
*/
readonly class BeforeModelUpdate implements EventSubscriberInterface
{
public function __construct(
private TrackerServiceInterface $trackerService
) {
}
public function handle(BeforeModelUpdateEvent $event): BeforeModelUpdateEvent
{
$payload = $event->getModel();
if (is_a($payload, UserInterface::class)) {
/** @var BaseModel&UserInterface $payload */
$this->trackerService->updateTracker($payload);
}
return $event;
}
public static function getSubscribedEvents(): array
{
return [
BeforeModelUpdateEvent::class => 'handle',
];
}
}