$resources */ public readonly array $resources, public readonly ?InteractionAction $action, /** @var list $receivers */ public readonly array $receivers, ) { parent::__construct(); } /** * @since 34.0.2 */ public function getUser(): IUser { if ($this->user instanceof IUser) { return $this->user; } $user = Server::get(IUserManager::class)->get($this->userId); if ($user === null) { throw new RuntimeException('User does not exist: ' . $this->userId); } return $this->user = $user; } /** * @return false|string Returns a user friendly translated message if the interaction is restricted. * @since 34.0.2 */ public function isInteractionRestricted(): false|string { $eventDispatcher = Server::get(IEventDispatcher::class); $params = [ $this->action instanceof InteractionAction ? $this->action::class : '?', $this->userId, $this->resources === [] ? '?' : implode(', ', array_map(static fn (InteractionResource $resource): string => $resource->getID(), $this->resources)), $this->receivers === [] ? '?' : implode(', ', array_map(static fn (InteractionReceiver $receiver): string => $receiver->getID() ?? $receiver::class, $this->receivers)), ]; try { $eventDispatcher->dispatchTyped($this); $eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent( 'Interaction %s from user %s on %s to %s is allowed.', $params, )); return false; } catch (InteractionRestrictedException $interactionRestrictedException) { $eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent( 'Interaction %s from user %s on %s to %s is restricted: ' . $interactionRestrictedException->getMessage(), $params, )); return $interactionRestrictedException->getHint(); } } }