14 private string $class;
23 $reflection = new \ReflectionClass($class);
24 if ($reflection->implementsInterface(
'\\Bitrix\\Rest\\Event\\EventBindInterface'))
26 $this->
class = $class;
44 $eventNames = $this->bind($names);
46 foreach ($eventNames as $internalName => $externalName)
48 $bindings[$externalName] = $this->getItemEventInfo($internalName, $this->class::getCallbackRestEvent());
61 private function bind(array $eventNames): array
65 foreach ($eventNames as $internalName => $externalName)
67 $isAssociativeArray = !is_numeric($internalName);
68 if ($isAssociativeArray)
70 $result[$internalName] = $externalName;
74 $internalName = $externalName;
75 $result[$internalName] = $this->makeExternalEventName($externalName);
82 private function getItemEventInfo(
string $eventName, array $callback): array
94 private function makeExternalEventName(
string $eventName): string
96 $converter =
new Converter(Converter::TO_SNAKE);
97 $eventName = str_replace(
'::',
'\\', $eventName);
98 $eventName = str_replace(
'\\',
'', $eventName);
99 $name = $converter->process($eventName);
101 return str_replace(
'_',
'.', $this->getModuleId().
'_'.$name);
108 private function getFilePath(
string $class): string
110 $reflector = new \ReflectionClass($class);
111 return Path::normalize($reflector->getFileName());
114 private function getModuleId(): string
116 return getModuleId($this->getFilePath($this->
class));
131 $event = $arParams[0] ??
null;
135 throw new RestException(
'event object not found trying to process event');
138 if ($event instanceof
Event)
140 $item = $event->getParameter(
'id');
141 $id = is_array($item) ? $item[
'ID']: $item;
146 throw new RestException(
'id not found trying to process event');