1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Mapper.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Socialnetwork\Control\Mapper;
6
7
use BackedEnum;
8
use Bitrix\Socialnetwork\Control\Command\AbstractCommand;
9
use Bitrix\Socialnetwork\Control\Mapper\Attribute\Map;
10
use Bitrix\Socialnetwork\ValueObjectInterface;
11
use ReflectionAttribute;
12
use ReflectionClass;
13
use ReflectionProperty;
14
15
class
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
}
Bitrix\Socialnetwork\Control\Command\AbstractCommand
Определения
AbstractCommand.php:24
Bitrix\Socialnetwork\Control\Mapper\Mapper
Определения
Mapper.php:16
Bitrix\Socialnetwork\Control\Mapper\Mapper\getFieldMappers
getFieldMappers(ReflectionProperty $property)
Определения
Mapper.php:63
Bitrix\Socialnetwork\Control\Mapper\Mapper\toArray
toArray(AbstractCommand $command)
Определения
Mapper.php:17
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Socialnetwork\ValueObjectInterface
Определения
ValueObjectInterface.php:6
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
bitrix
modules
socialnetwork
lib
Control
Mapper
Mapper.php
Создано системой
1.14.0