Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/socialnetwork/lib/Control/Mapper/ |
Upload File : |
<?php declare(strict_types=1); namespace Bitrix\Socialnetwork\Control\Mapper; use BackedEnum; use Bitrix\Socialnetwork\Control\Command\AbstractCommand; use Bitrix\Socialnetwork\Control\Mapper\Attribute\Map; use Bitrix\Socialnetwork\ValueObjectInterface; use ReflectionClass; use ReflectionProperty; class Mapper { public function toArray(AbstractCommand $command): array { $data = []; $reflection = new ReflectionClass($command); $properties = $reflection->getProperties(); foreach ($properties as $property) { if (!$property->isInitialized($command)) { continue; } $value = $property->getValue($command); if ($value instanceof ValueObjectInterface) { $value = $value->getValue(); } elseif ($value instanceof BackedEnum) { $value = $value->value; } $mappers = $this->getFieldMappers($property); foreach ($mappers as $mapper) { [$fieldName, $fieldValue] = $mapper->getNameAndValue($value); if ($fieldValue === null) { continue; } if (!isset($data[$fieldName])) { $data[$fieldName] = $fieldValue; } } } return $data; } /** @return Map[] */ protected function getFieldMappers(ReflectionProperty $property): array { $result = []; $attributes = $property->getAttributes(); foreach ($attributes as $attributeReflection) { $attribute = $attributeReflection->newInstance(); if ($attribute instanceof Map) { $result[] = $attribute; } } return $result; } }