• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Dto/Property.php
  • Класс: Bitrix\Crm\Dto\Property
  • Вызов: Property::getCaster
private function getCaster(Dto $dto): ?\Bitrix\Crm\Dto\Caster
{
	if (!$this->property->hasType())
	{
		throw new DtoPropertyTypeIsUndefined($dto, $this->getName());
	}
	$propertyType = $this->property->getType();
	$caster = $this->object->getCastByPropertyName($this->getName());

	if (!$caster)
	{
		$propertyTypeName = $propertyType->getName();
		if ($propertyType->isBuiltin())
		{
			switch ($propertyTypeName)
			{
				case 'string':
					$caster = new \Bitrix\Crm\Dto\Caster\StringCaster();
					break;
				case 'int':
					$caster = new \Bitrix\Crm\Dto\Caster\IntCaster();
					break;
				case 'bool':
					$caster = new \Bitrix\Crm\Dto\Caster\BoolCaster();
					break;
			}
			if (!$caster)
			{
				throw new ArgumentOutOfRangeException('Caster for type`' . $propertyTypeName . '` was not found');
			}
		}
		else // property type is a class
		{
			if ($propertyTypeName === TextWithTranslationDto::class)
			{
				$caster = new Caster\TextWithTranslationCaster();
			}
			else
			{
				$caster = new \Bitrix\Crm\Dto\Caster\ObjectCaster($propertyTypeName);
			}
		}
	}
	$caster->nullable($propertyType->allowsNull());

	return $caster;
}