• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/v2/BaseEntity.php
  • Класс: BitrixCatalogv2BaseEntity
  • Вызов: BaseEntity::getChildCollections
protected function getChildCollections(bool $initCollections = false): Generator
{
	$collectionPostfix = 'Collection';
	$collectionPostfixLength = mb_strlen($collectionPostfix);
	$parentCollection = "parent{$collectionPostfix}";

	foreach ((new ReflectionObject($this))->getProperties() as $property)
	{
		$propertyName = $property->getName();

		if (
			$propertyName !== $parentCollection
			&& mb_substr($propertyName, -$collectionPostfixLength) === $collectionPostfix
		)
		{
			$property->setAccessible(true);
			$value = $property->getValue($this);

			if ($value === null && $initCollections)
			{
				$propertyGetter = "get{$propertyName}";

				if (is_callable([$this, $propertyGetter]))
				{
					$value = $this->$propertyGetter();
				}
			}

			if ($value instanceof BaseCollection)
			{
				yield $value;
			}
		}
	}
}