• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/engine/crawler.php
  • Класс: BitrixMainEngineCrawler
  • Вызов: Crawler::getFilesUnderNamespace
private function getFilesUnderNamespace($namespace)
{
	$path = ltrim($namespace, "\");    // fix web env
	$path = strtolower($path);

	$documentRoot = Context::getCurrent()->getServer()->getDocumentRoot();

	if (preg_match("#[^\\/a-zA-Z0-9_]#", $path))
	{
		return array();
	}

	$path = str_replace('\', '/', $path);
	$pathParts = explode("/", $path);

	if ($pathParts[0] === "bitrix")
	{
		array_shift($pathParts);

		if (empty($pathParts))
		{
			return array();
		}

		$module = array_shift($pathParts);
		if ($module == null || empty($pathParts))
		{
			return array();
		}
	}
	else
	{
		$module1 = array_shift($pathParts);
		$module2 = array_shift($pathParts);
		if ($module1 == null || $module2 == null || empty($pathParts))
		{
			return array();
		}

		$module = $module1 . "." . $module2;
	}

	$rootFolder = $documentRoot . "/bitrix/modules/" . $module . "/lib/" . implode("/", $pathParts);

	$classes = array();
	foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootFolder)) as $file)
	{
		/** @var $file SplFileInfo */
		if (!$file->isFile())
		{
			continue;
		}

		if ($file->getPath() === $rootFolder)
		{
			$classes[] = $namespace . '\' . $file->getBasename('.php');
			continue;
		}

		$relativeFolder = trim(mb_substr($file->getPath(), mb_strlen($rootFolder)), '\/');
		$classes[] = $namespace . '\' . strtr($relativeFolder, array('/' => '\')) . '\' . $file->getBasename('.php');
	}

	return $classes;
}