• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/eventmanager.php
  • Класс: BitrixMainEventManager
  • Вызов: EventManager::sendToEventHandler
protected function sendToEventHandler(array $handler, Event $event)
{
	try
	{
		$result = true;
		$includeResult = true;

		$event->addDebugInfo($handler);

		if (isset($handler['TO_MODULE_ID']) && !empty($handler['TO_MODULE_ID']) && ($handler['TO_MODULE_ID'] != 'main'))
		{
			$result = Loader::includeModule($handler['TO_MODULE_ID']);
		}
		elseif (isset($handler['TO_PATH']) && !empty($handler['TO_PATH']))
		{
			$path = ltrim($handler['TO_PATH'], '/');
			if (($path = Loader::getLocal($path)) !== false)
			{
				$includeResult = include_once($path);
			}
		}
		elseif (isset($handler['FULL_PATH']) && !empty($handler['FULL_PATH']) && IOFile::isFileExists($handler['FULL_PATH']))
		{
			$includeResult = include_once($handler['FULL_PATH']);
		}

		$event->addDebugInfo($result);

		if ($result)
		{
			if (isset($handler['TO_METHOD_ARG']) && is_array($handler['TO_METHOD_ARG']) && !empty($handler['TO_METHOD_ARG']))
			{
				$args = $handler['TO_METHOD_ARG'];
			}
			else
			{
				$args = [];
			}

			if ($handler['VERSION'] > 1)
			{
				$args[] = $event;
			}
			else
			{
				$args = array_merge($args, array_values($event->getParameters()));
			}

			$callback = null;
			if (isset($handler['CALLBACK']))
			{
				$callback = $handler['CALLBACK'];
			}
			elseif (!empty($handler['TO_CLASS']) && !empty($handler['TO_METHOD']) && class_exists($handler['TO_CLASS']))
			{
				$callback = [$handler['TO_CLASS'], $handler['TO_METHOD']];
			}

			if ($callback != null)
			{
				$result = call_user_func_array($callback, $args);
			}
			else
			{
				$result = $includeResult;
			}

			if (($result != null) && !($result instanceof EventResult))
			{
				$result = new EventResult(EventResult::UNDEFINED, $result, $handler['TO_MODULE_ID'] ?? null);
			}

			$event->addDebugInfo($result);

			if ($result != null)
			{
				$event->addResult($result);
			}
		}
	}
	catch (Exception $ex)
	{
		if ($event->isDebugOn())
		{
			$event->addException($ex);
		}
		else
		{
			throw $ex;
		}
	}
}