Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
jsonconverter.php
1
<?
8
namespace
Bitrix\Fileman\Block\Content
;
9
10
use
Bitrix\Main\Web\Json
;
11
use
Bitrix\Main\ArgumentException
;
12
use
Bitrix\Main\Localization\Loc
;
13
14
Loc::loadMessages
(__FILE__);
15
16
class
JsonConverter
implements
IConverter
17
{
24
public
static
function
isValid
($string)
25
{
26
$string = trim($string);
27
$char = mb_substr($string, 0, 1);
28
if
(!in_array($char, array(
'{'
,
'['
)))
29
{
30
return
false
;
31
}
32
$char = mb_substr($string, -1);
33
if
(!in_array($char, array(
'}'
,
']'
)))
34
{
35
return
false
;
36
}
37
38
try
39
{
40
$r = Json::decode($string);
41
return
is_array($r);
42
}
43
catch
(
ArgumentException
$exception)
44
{
45
return
false
;
46
}
47
}
48
55
public
static
function
toArray
($string)
56
{
57
$blockContent =
new
BlockContent
();
58
try
59
{
60
$list = Json::decode($string);
61
if
(!is_array($list))
62
{
63
return
$blockContent;
64
}
65
}
66
catch
(
ArgumentException
$exception)
67
{
68
return
$blockContent;
69
}
70
71
foreach
($list as $item)
72
{
73
$type = trim($item[
'type'
]);
74
$place = trim($item[
'place'
]);
75
$value = trim($item[
'value'
]);
76
$blockContent->add($type, $place, $value);
77
}
78
79
return
$blockContent;
80
}
81
}
Bitrix\Fileman\Block\Content\BlockContent
Definition
blockcontent.php:15
Bitrix\Fileman\Block\Content\JsonConverter
Definition
jsonconverter.php:17
Bitrix\Fileman\Block\Content\JsonConverter\isValid
static isValid($string)
Definition
jsonconverter.php:24
Bitrix\Fileman\Block\Content\JsonConverter\toArray
static toArray($string)
Definition
jsonconverter.php:55
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Fileman\Block\Content\IConverter
Definition
iconverter.php:19
Bitrix\Fileman\Block\Content
Definition
blockcontent.php:8
modules
fileman
lib
block
content
jsonconverter.php
Создано системой
1.10.0