1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
externalizer.php
См. документацию.
1
<?php
2
3
4
namespace
Bitrix\Rest\Integration;
5
6
7
use Bitrix\Main\Engine\Response\Converter;
8
use Bitrix\Main\Engine\Response\DataType\Page;
9
use Bitrix\Main\Result;
10
use Bitrix\Main\Type\Contract\Arrayable;
11
17
final
class
Externalizer
extends
ModificationFieldsBase
18
implements
Arrayable
19
{
20
public
function
__construct
(
ViewManager
$manager
,
$data
= [])
21
{
22
$this->
setFormat
([
23
self::TO_WHITE_LIST,
24
self::TO_CAMEL,
25
self::SORTING_KEYS
26
]);
27
parent::__construct(
$manager
,
$data
);
28
}
29
30
public
function
process
()
31
{
32
$r =
new
Result
();
33
34
$data
= $this->
getData
();
35
$id = $this->getIdList(
$data
);
36
37
$data
=
$data
[$id];
38
if
(in_array(self::TO_WHITE_LIST, $this->format))
39
{
40
$data
= $this->externalize(
$data
);
41
}
42
43
if
(in_array(self::TO_CAMEL, $this->format))
44
{
45
$data
= static::convertKeysToCamelCase([$id=>
$data
]);
46
}
47
48
if
(in_array(self::SORTING_KEYS, $this->format))
49
{
50
$data
= static::multiSortKeysArray(
$data
);
51
}
52
53
return
$r->setData([
'data'
=>
$data
]);
54
}
55
56
public
function
toArray
()
57
{
58
return
$this->
process
()->getData()[
'data'
];
59
}
60
61
static
public
function
multiSortKeysArray
(
array
$data
)
62
{
63
ksort(
$data
, SORT_NATURAL);
64
65
foreach
(
$data
as
$k
=>&$item)
66
{
67
if
(is_array($item))
68
$item = static::multiSortKeysArray($item);
69
}
70
71
return
$data
;
72
}
73
79
private
function
externalize(
$fields
)
80
{
81
$name
= $this->
getName
();
82
$controller
= $this->
getController
();
83
$view = $this->
getView
(
$controller
);
84
85
if
(
$name
==
'getfields'
){}
86
elseif
(
$name
==
'delete'
){}
87
elseif
(
$name
==
'get'
88
||
$name
==
'add'
89
||
$name
==
'update'
)
90
{
91
$fields
= $view->externalizeFieldsGet(
$fields
);
92
}
93
elseif
(
$name
==
'list'
)
94
{
95
$fields
= $view->externalizeListFields(
$fields
);
96
}
97
else
98
{
99
$fields
= $view->externalizeResult(
$name
,
$fields
);
100
}
101
102
return
$fields
;
103
}
104
110
private
function
getIdList(
$data
)
111
{
112
return
key(
$data
);
113
}
114
115
static
public
function
convertKeysToCamelCase
(
$fields
)
116
{
117
return
Converter::toJson()
118
->process(
$fields
);
119
}
120
121
public
function
getPage
(
Page
$page
)
122
{
123
$id = static::convertKeysToCamelCase(
$page
->getId());
124
return
new
Page
($id, $this->
toArray
()[$id],
$page
->getTotalCount());
125
}
126
}
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
Bitrix\Rest\Integration\Externalizer
Определения
externalizer.php:19
Bitrix\Rest\Integration\Externalizer\getPage
getPage(Page $page)
Определения
externalizer.php:121
Bitrix\Rest\Integration\Externalizer\multiSortKeysArray
static multiSortKeysArray(array $data)
Определения
externalizer.php:61
Bitrix\Rest\Integration\Externalizer\convertKeysToCamelCase
static convertKeysToCamelCase($fields)
Определения
externalizer.php:115
Bitrix\Rest\Integration\Externalizer\__construct
__construct(ViewManager $manager, $data=[])
Определения
externalizer.php:20
Bitrix\Rest\Integration\Externalizer\toArray
toArray()
Определения
externalizer.php:56
Bitrix\Rest\Integration\Externalizer\process
process()
Определения
externalizer.php:30
Bitrix\Rest\Integration\ModificationFieldsBase
Определения
modificationfieldsbase.php:10
Bitrix\Rest\Integration\ModificationFieldsBase\getView
getView(Controller $controller)
Определения
modificationfieldsbase.php:73
Bitrix\Rest\Integration\ModificationFieldsBase\$controller
$controller
Определения
modificationfieldsbase.php:22
Bitrix\Rest\Integration\ModificationFieldsBase\getName
getName()
Определения
modificationfieldsbase.php:43
Bitrix\Rest\Integration\ModificationFieldsBase\$manager
$manager
Определения
modificationfieldsbase.php:20
Bitrix\Rest\Integration\ModificationFieldsBase\$data
$data
Определения
modificationfieldsbase.php:17
Bitrix\Rest\Integration\ModificationFieldsBase\getData
getData()
Определения
modificationfieldsbase.php:68
Bitrix\Rest\Integration\ModificationFieldsBase\getController
getController()
Определения
modificationfieldsbase.php:63
Bitrix\Rest\Integration\ModificationFieldsBase\$name
$name
Определения
modificationfieldsbase.php:18
Bitrix\Rest\Integration\ModificationFieldsBase\setFormat
setFormat($format)
Определения
modificationfieldsbase.php:58
Bitrix\Rest\Integration\ViewManager
Определения
viewmanager.php:11
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Main\Type\Contract\Arrayable
Определения
arrayable.php:6
$name
$name
Определения
menu_edit.php:35
Bitrix\Main\Page
Определения
aliases.php:54
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$page
$page
Определения
order_form.php:33
$k
$k
Определения
template_pdf.php:567
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
rest
lib
integration
externalizer.php
Создано системой
1.14.0