Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
RestAdapter.php
1<?php
2
3namespace Bitrix\Im\V2\Rest;
4
6{
10 protected array $entities = [];
12
14 {
15 $this->entities = $entities ?? [];
16 }
17
18 public function toRestFormat(array $options = []): array
19 {
20 $popupData = new PopupData([]);
21
22 foreach ($this->entities as $entity)
23 {
24 if ($entity instanceof PopupDataAggregatable)
25 {
26 $popupData->merge($entity->getPopupData($options['POPUP_DATA_EXCLUDE'] ?? []));
27 }
28 }
29
30 if (isset($this->additionalPopupData))
31 {
32 $popupData->merge($this->additionalPopupData);
33 }
34
35 $rest = $popupData->toRestFormat($options);
36
37 if (empty($rest))
38 {
39 if (count($this->entities) === 1)
40 {
41 return $this->entities[0]->toRestFormat($options);
42 }
43 }
44
45 foreach ($this->entities as $entity)
46 {
47 $rest[$entity::getRestEntityName()] = $entity->toRestFormat($options);
48 }
49
50 return $rest;
51 }
52
53 public function setAdditionalPopupData(PopupData $popupData): self
54 {
55 $this->additionalPopupData = $popupData;
56
57 return $this;
58 }
59
60 public function addEntities(RestConvertible ...$entities): self
61 {
62 foreach ($entities as $entity)
63 {
64 $this->entities[] = $entity;
65 }
66
67 return $this;
68 }
69}
addEntities(RestConvertible ... $entities)
__construct(RestConvertible ... $entities)
setAdditionalPopupData(PopupData $popupData)
toRestFormat(array $options=[])