1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AbstractBaseDto.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
9use Bitrix\Socialnetwork\Collab\Controller\Trait\ConvertRequestToArrayTrait;
10use ReflectionClass;
11use ReflectionProperty;
12
13abstract class AbstractBaseDto implements Arrayable
14{
15 use ConvertRequestToArrayTrait;
16
17 public static function createFromRequest(mixed $request): static
18 {
19 $dto = [];
20
21 $requestData = static::convertRequest($request);
22
23 $reflection = new ReflectionClass(static::class);
24
25 foreach ($requestData as $key => $value)
26 {
27 if ($reflection->hasProperty($key))
28 {
29 $dto[$key] = static::cast($key, $value);
30 }
31 }
32
33 return new static(...$dto);
34 }
35
36 protected static function cast(string $key, mixed $value): mixed
37 {
38 $reflection = new ReflectionProperty(static::class, $key);
39 $type = $reflection->getType()?->getName();
40 if ($type === null)
41 {
42 return $value;
43 }
44
45 $metaType = MetaTypeConverter::getMetaType(static::class, $key);
46 if ($metaType !== null)
47 {
48 return MetaTypeConverter::convert($metaType, $value);
49 }
50
51 return match ($type)
52 {
53 'int' => (int)$value,
54 'float' => (float)$value,
55 'string' => (string)$value,
56 'array' => (array)$value,
57 'bool' => (bool)$value,
58 default => $value,
59 };
60 }
61
62 public function toArray(): array
63 {
64 $data = [];
65 foreach ($this as $key => $value)
66 {
67 if ($value !== null)
68 {
69 $data[$key] = $value;
70 }
71 }
72
73 return $data;
74 }
75}
$type
Определения options.php:106
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static cast(string $key, mixed $value)
Определения AbstractBaseDto.php:36
static convert(PropertyMetaType $type, mixed $value)
Определения MetaTypeConverter.php:30
$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
if(empty($signedUserToken)) $key
Определения quickway.php:257