-
Notifications
You must be signed in to change notification settings - Fork 88
/
MyFeatureEventSubscriber.php
36 lines (30 loc) · 1.11 KB
/
MyFeatureEventSubscriber.php
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
<?php declare(strict_types=1);
namespace App\EventSubscriber;
use App\Event\MyFeatureEvent;
use Ibexa\Contracts\ActivityLog\ActivityLogServiceInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MyFeatureEventSubscriber implements EventSubscriberInterface
{
private ActivityLogServiceInterface $activityLogService;
public function __construct(ActivityLogServiceInterface $activityLogService)
{
$this->activityLogService = $activityLogService;
}
public static function getSubscribedEvents(): array
{
return [
MyFeatureEvent::class => 'onMyFeatureEvent',
];
}
public function onMyFeatureEvent(MyFeatureEvent $event): void
{
/** @var App\MyFeature\MyFeature $object */
$object = $event->getObject();
$className = get_class($object);
$id = (string)$object->id;
$action = $event->getAction();
$activityLog = $this->activityLogService->build($className, $id, $action);
$activityLog->setObjectName($object->name);
$this->activityLogService->save($activityLog);
}
}