1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Mapper.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Control\Mapper;
6
7use BackedEnum;
8use Bitrix\Socialnetwork\Control\Command\AbstractCommand;
9use Bitrix\Socialnetwork\Control\Mapper\Attribute\Map;
10use Bitrix\Socialnetwork\ValueObjectInterface;
11use ReflectionAttribute;
12use ReflectionClass;
13use ReflectionProperty;
14
15class Mapper
16{
17 public function toArray(AbstractCommand $command): array
18 {
19 $data = [];
20 $reflection = new ReflectionClass($command);
21 $properties = $reflection->getProperties();
22
23 foreach ($properties as $property)
24 {
25 if (!$property->isInitialized($command))
26 {
27 continue;
28 }
29
30 $value = $property->getValue($command);
31
32 if ($value instanceof ValueObjectInterface)
33 {
34 $value = $value->getValue();
35 }
36 elseif ($value instanceof BackedEnum)
37 {
38 $value = $value->value;
39 }
40
41 $mappers = $this->getFieldMappers($property);
42
43 foreach ($mappers as $mapper)
44 {
45 [$fieldName, $fieldValue] = $mapper->getNameAndValue($value);
46
47 if ($fieldValue === null)
48 {
49 continue;
50 }
51
52 if (!isset($data[$fieldName]))
53 {
54 $data[$fieldName] = $fieldValue;
55 }
56 }
57 }
58
59 return $data;
60 }
61
63 protected function getFieldMappers(ReflectionProperty $property): array
64 {
65 $result = [];
66
67 $attributes = $property->getAttributes(Map::class, ReflectionAttribute::IS_INSTANCEOF);
68
69 foreach ($attributes as $attributeReflection)
70 {
71 $result[] = $attributeReflection->newInstance();
72 }
73
74 return $result;
75 }
76}
getFieldMappers(ReflectionProperty $property)
Определения Mapper.php:63
toArray(AbstractCommand $command)
Определения Mapper.php:17
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393