createEventHandler($request); $this->eventManager->eventRegister($eventHandler); $handler = $handler->handle($request); try { if ($handler->getStatusCode() < 300) { if (isset($eventHandler->request)) { if ($eventHandler->request->getAttribute('lean-api.security-action:attribute')) { $this->actionLogController->add($eventHandler->request, []); } } } } catch(\Throwable $ex) { if (getenv('DEBUG')) { throw $ex; } } return $handler; } protected function createEventHandler(ServerRequestInterface $request) : object { return new class($this->leanApiFormFactory->securityActionLogSaveContext($request)) implements RoutingMapRoutes { public readonly ServerRequestInterface $request; public function __construct( public readonly Form\Security\ActionLogContext $context, ) {} public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface &$request, Route $attribute): void { if (in_array($request->getMethod(), [ 'PATCH', 'POST', 'PUT', 'DELETE' ])) { $objectReflection = ObjectReflection::fromClass($attribute->class, null)->reflectClass(); $actionLog = $objectReflection->methods[$attribute->classMethod]->getAttribute(\Lean\Api\Attribute\Security\ActionLog::class); if ($actionLog) { $this->context->event = $attribute->name; $this->context->method = $request->getMethod(); $request = $this->request = $request ->withAttribute('lean-api.security-action:attribute', $actionLog->object) ->withAttribute('lean-api.security-action:context', $this->context); } } } }; } }