Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ArrayLib.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Calc\Libs
;
4
5
use
Bitrix\Bizproc\Calc\Arguments
;
6
use
Bitrix\Main\Localization\Loc
;
7
8
class
ArrayLib
extends
BaseLib
9
{
10
public
function
getFunctions
(): array
11
{
12
return
[
13
'implode'
=> [
14
'args'
=>
true
,
15
'func'
=>
'callImplode'
,
16
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_IMPLODE_DESCRIPTION'
),
17
],
18
'explode'
=> [
19
'args'
=>
true
,
20
'func'
=>
'callExplode'
,
21
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_EXPLODE_DESCRIPTION'
),
22
],
23
'merge'
=> [
24
'args'
=>
true
,
25
'func'
=>
'callMerge'
,
26
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_MERGE_DESCRIPTION'
),
27
],
28
'shuffle'
=> [
29
'args'
=>
true
,
30
'func'
=>
'callShuffle'
,
31
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_SHUFFLE_DESCRIPTION'
),
32
],
33
'firstvalue'
=> [
34
'args'
=>
true
,
35
'func'
=>
'callFirstValue'
,
36
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_FIRSTVALUE_DESCRIPTION'
),
37
],
38
'swirl'
=> [
39
'args'
=>
true
,
40
'func'
=>
'callSwirl'
,
41
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_SWIRL_DESCRIPTION'
),
42
],
43
];
44
}
45
46
public
function
callImplode
(
Arguments
$args)
47
{
48
$glue = $args->
getFirst
();
49
50
if
(!is_scalar($glue))
51
{
52
return
null
;
53
}
54
55
$pieces = \CBPHelper::makeArrayFlat($args->
getSecond
());
56
57
if
(!$pieces)
58
{
59
return
''
;
60
}
61
62
return
implode($glue, $pieces);
63
}
64
65
public
function
callExplode
(
Arguments
$args)
66
{
67
$delimiter = $args->
getFirst
();
68
$str = $args->
getSecondSingle
();
69
70
if
(empty($delimiter) || !is_scalar($str) || !is_scalar($delimiter))
71
{
72
return
null
;
73
}
74
75
$str = (string)$str;
76
77
return
explode($delimiter, $str);
78
}
79
80
public
function
callMerge
(
Arguments
$args)
81
{
82
$arrays = $args->
getArray
();
83
84
foreach
($arrays as &$a)
85
{
86
$a = is_object($a) ? [$a] : (array)$a;
87
}
88
89
return
array_merge(...$arrays);
90
}
91
92
public
function
callShuffle
(
Arguments
$args)
93
{
94
$array = array_filter($args->
getFlatArray
(), fn ($arg) => $arg !==
null
);
95
shuffle($array);
96
97
return
$array;
98
}
99
100
public
function
callFirstValue
(
Arguments
$args)
101
{
102
$array = $args->
getFlatArray
();
103
104
return
$array[0] ??
null
;
105
}
106
107
public
function
callSwirl
(
Arguments
$args)
108
{
109
$array = array_values(
110
array_filter($args->
getFlatArray
(), fn ($arg) => $arg !==
null
)
111
);
112
113
if
(count($array) <= 1)
114
{
115
return
$array;
116
}
117
118
return
array_merge(array_slice($array, 1), [$array[0]]);
119
}
120
}
Bitrix\Bizproc\Calc\Arguments
Definition
Arguments.php:6
Bitrix\Bizproc\Calc\Arguments\getArray
getArray()
Definition
Arguments.php:28
Bitrix\Bizproc\Calc\Arguments\getFlatArray
getFlatArray()
Definition
Arguments.php:33
Bitrix\Bizproc\Calc\Arguments\getSecondSingle
getSecondSingle()
Definition
Arguments.php:65
Bitrix\Bizproc\Calc\Arguments\getSecond
getSecond()
Definition
Arguments.php:57
Bitrix\Bizproc\Calc\Arguments\getFirst
getFirst()
Definition
Arguments.php:41
Bitrix\Bizproc\Calc\Libs\ArrayLib
Definition
ArrayLib.php:9
Bitrix\Bizproc\Calc\Libs\ArrayLib\getFunctions
getFunctions()
Definition
ArrayLib.php:10
Bitrix\Bizproc\Calc\Libs\ArrayLib\callFirstValue
callFirstValue(Arguments $args)
Definition
ArrayLib.php:100
Bitrix\Bizproc\Calc\Libs\ArrayLib\callImplode
callImplode(Arguments $args)
Definition
ArrayLib.php:46
Bitrix\Bizproc\Calc\Libs\ArrayLib\callMerge
callMerge(Arguments $args)
Definition
ArrayLib.php:80
Bitrix\Bizproc\Calc\Libs\ArrayLib\callSwirl
callSwirl(Arguments $args)
Definition
ArrayLib.php:107
Bitrix\Bizproc\Calc\Libs\ArrayLib\callShuffle
callShuffle(Arguments $args)
Definition
ArrayLib.php:92
Bitrix\Bizproc\Calc\Libs\ArrayLib\callExplode
callExplode(Arguments $args)
Definition
ArrayLib.php:65
Bitrix\Bizproc\Calc\Libs\BaseLib
Definition
BaseLib.php:6
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Bizproc\Calc\Libs
Definition
ArrayLib.php:3
modules
bizproc
lib
Calc
Libs
ArrayLib.php
Создано системой
1.10.0