1C-Bitrix
25.700.0
Toggle main menu visibility
Титульная страница
Пространства имен
Пространства имен
Члены пространств имен
Указатель
$
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
Функции
_
a
c
d
e
f
g
h
i
k
l
m
o
p
r
s
t
u
v
w
Переменные
$
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
t
v
w
Перечисления
a
b
c
d
e
f
g
l
m
n
o
p
r
s
t
u
v
w
Элементы перечислений
a
b
c
d
e
f
g
i
l
m
n
o
p
r
s
t
u
v
w
Структуры данных
Структуры данных
Алфавитный указатель структур данных
Иерархия классов
Поля структур
Указатель
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Функции
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Переменные
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Перечисления
Элементы перечислений
Файлы
Файлы
Список членов всех файлов
Указатель
$
(
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
x
y
б
в
к
л
о
п
с
т
ю
Функции
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Переменные
$
(
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
y
б
в
к
л
о
п
с
т
ю
Блог
Хостинг
•
Указатель
Структуры данных
Пространства имен
Файлы
Функции
Переменные
Перечисления
Элементы перечислений
Страницы
Загрузка...
Поиск...
Не найдено
validator.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Bizproc;
4
5
use Bitrix\Main\Localization\Loc;
6
use Bitrix\Bizproc\Exception\ValidationException;
7
8
class
Validator
9
{
10
const
TYPE_ARRAY
=
'array'
;
11
const
TYPE_NUMERIC
=
'numeric'
;
12
const
TYPE_STRING
=
'string'
;
13
14
protected
array
$dirtyValues
;
15
protected
array
$pureValues
= [];
16
17
public
function
__construct
(
array
$values)
18
{
19
Loc::loadMessages(__FILE__);
20
$this->dirtyValues = $values;
21
}
17
public
function
__construct
(
array
$values) {
…
}
22
23
public
function
getPureValues
():
array
24
{
25
return
$this->pureValues
;
26
}
23
public
function
getPureValues
():
array
{
…
}
27
28
protected
function
validate
(
string
$type
, $value): bool
29
{
30
if
(
$type
=== self::TYPE_ARRAY)
31
{
32
return
is_array($value);
33
}
34
elseif
(
$type
=== self::TYPE_NUMERIC)
35
{
36
return
is_numeric($value);
37
}
38
else
39
{
40
return
is_string($value);
41
}
42
}
28
protected
function
validate
(
string
$type
, $value): bool {
…
}
43
44
public
function
validateArray
(
string
$name
,
string
$keyType = self::TYPE_NUMERIC,
45
string
$valueType = self::TYPE_STRING): self
46
{
47
if
(!isset($this->dirtyValues[
$name
]))
48
{
49
return
$this;
50
}
51
52
foreach
($this->dirtyValues[
$name
] as
$key
=> $value)
53
{
54
if
(!$this->
validate
($keyType,
$key
))
55
{
56
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_ARRAY_KEY"
,
57
[
"#name#"
=>
$name
,
'#val#'
=>
$key
]));
58
}
59
if
(!$this->
validate
($valueType, $value))
60
{
61
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_ARRAY_VAL"
,
62
[
"#name#"
=>
$name
,
'#val#'
=>
$key
]));
63
}
64
}
65
66
if
(!is_array($this->dirtyValues[
$name
]))
67
{
68
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_IS_ARRAY"
, [
"#name#"
=>
$name
]));
69
}
70
71
$this->
setPureValue
($name);
72
return
$this;
73
}
44
public
function
validateArray
(
string
$name
,
string
$keyType = self::TYPE_NUMERIC, {
…
}
74
75
public
function
validateNumeric
(
string
$name
,
int
$min = 0,
int
$max
= 0): self
76
{
77
if
(!isset($this->dirtyValues[
$name
]))
78
{
79
return
$this;
80
}
81
82
if
(!is_numeric($this->dirtyValues[
$name
]))
83
{
84
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_IS_NUM"
, [
"#name#"
=>
$name
]));
85
}
86
87
$val
= (int)$this->dirtyValues[
$name
];
88
89
if
($min &&
$val
< $min)
90
{
91
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_NUM_MIN"
,
92
[
"#name#"
=>
$name
,
'#min#'
=> $min]));
93
}
94
95
if
(
$max
&&
$val
>
$max
)
96
{
97
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_NUM_MAX"
,
98
[
"#name#"
=>
$name
,
'#max#'
=>
$max
]));
99
}
100
101
$this->
setPureValue
($name);
102
return
$this;
103
}
75
public
function
validateNumeric
(
string
$name
,
int
$min = 0,
int
$max
= 0): self {
…
}
104
105
public
function
validateString
(
string
$name
,
int
$minLen = 0,
int
$maxLen = 0): self
106
{
107
if
(!isset($this->dirtyValues[
$name
]))
108
{
109
return
$this;
110
}
111
112
$val
= $this->dirtyValues[
$name
];
113
114
if
(!is_string(
$val
))
115
{
116
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_IS_STRING"
, [
"#name#"
=>
$name
]));
117
}
118
119
if
($minLen && mb_strlen(
$val
) < $minLen)
120
{
121
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_STRING_MIN"
,
122
[
"#name#"
=>
$name
,
'#min#'
=> $minLen]));
123
}
124
125
if
($maxLen && mb_strlen(
$val
) > $maxLen)
126
{
127
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_STRING_MAX"
,
128
[
"#name#"
=>
$name
,
'#max#'
=> $maxLen]));
129
}
130
131
$this->
setPureValue
($name);
132
return
$this;
133
}
105
public
function
validateString
(
string
$name
,
int
$minLen = 0,
int
$maxLen = 0): self {
…
}
134
135
public
function
validateRegExp
(
string
$name
,
string
$pattern
): self
136
{
137
if
(!isset($this->dirtyValues[
$name
]))
138
{
139
return
$this;
140
}
141
142
if
(!preg_match(
$pattern
, $this->dirtyValues[
$name
]))
143
{
144
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_REGEXP"
,
145
[
"#name#"
=>
$name
,
"#pattern#"
=>
$pattern
]));
146
}
147
148
$this->
setPureValue
($name);
149
return
$this;
150
}
135
public
function
validateRegExp
(
string
$name
,
string
$pattern
): self {
…
}
151
152
public
function
validateEnum
(
string
$name
,
array
$enum): self
153
{
154
if
(!isset($this->dirtyValues[
$name
]))
155
{
156
return
$this;
157
}
158
159
if
(!in_array($this->dirtyValues[
$name
], $enum))
160
{
161
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_ENUM"
,
162
[
"#name#"
=>
$name
,
"#enum#"
=> implode(
'", "'
, $enum)]));
163
}
164
165
$this->
setPureValue
($name);
166
return
$this;
167
}
152
public
function
validateEnum
(
string
$name
,
array
$enum): self {
…
}
168
169
public
function
validateRequire
(
string
$name
): self
170
{
171
if
(!isset($this->dirtyValues[
$name
]))
172
{
173
throw
new
ValidationException
(Loc::getMessage(
"BIZPROC_VALIDATOR_REQUIRE"
, [
"#name#"
=>
$name
]));
174
}
175
176
$this->
setPureValue
($name);
177
return
$this;
178
}
169
public
function
validateRequire
(
string
$name
): self {
…
}
179
180
public
function
setDefault
(
string
$name
, $value): self
181
{
182
if
(!isset($this->dirtyValues[
$name
]) && !isset($this->pureValues[
$name
]))
183
{
184
$this->pureValues[
$name
] = $value;
185
}
186
187
return
$this;
188
}
180
public
function
setDefault
(
string
$name
, $value): self {
…
}
189
190
public
function
setPureValue
(
$name
): self
191
{
192
if
(isset($this->dirtyValues[
$name
]) && !isset($this->pureValues[
$name
]))
193
{
194
$this->pureValues[
$name
] = $this->dirtyValues[
$name
];
195
}
196
197
return
$this;
198
}
190
public
function
setPureValue
(
$name
): self {
…
}
199
200
public
function
convertToInt
(
string
$name
): self
201
{
202
if
(isset($this->dirtyValues[
$name
]))
203
{
204
$this->dirtyValues[
$name
] = (int)$this->dirtyValues[
$name
];
205
}
206
207
if
(isset($this->pureValues[
$name
]))
208
{
209
$this->pureValues[
$name
] = (int)$this->pureValues[
$name
];
210
}
211
212
return
$this;
213
}
200
public
function
convertToInt
(
string
$name
): self {
…
}
214
}
8
class
Validator
{
…
};
$type
$type
Определения
options.php:106
Bitrix\Bizproc\Exception\ValidationException
Определения
validationexception.php:6
Bitrix\Bizproc\Validator
Определения
validator.php:9
Bitrix\Bizproc\Validator\TYPE_NUMERIC
const TYPE_NUMERIC
Определения
validator.php:11
Bitrix\Bizproc\Validator\$dirtyValues
array $dirtyValues
Определения
validator.php:14
Bitrix\Bizproc\Validator\TYPE_ARRAY
const TYPE_ARRAY
Определения
validator.php:10
Bitrix\Bizproc\Validator\$pureValues
array $pureValues
Определения
validator.php:15
Bitrix\Bizproc\Validator\validateArray
validateArray(string $name, string $keyType=self::TYPE_NUMERIC, string $valueType=self::TYPE_STRING)
Определения
validator.php:44
Bitrix\Bizproc\Validator\setDefault
setDefault(string $name, $value)
Определения
validator.php:180
Bitrix\Bizproc\Validator\validateString
validateString(string $name, int $minLen=0, int $maxLen=0)
Определения
validator.php:105
Bitrix\Bizproc\Validator\getPureValues
getPureValues()
Определения
validator.php:23
Bitrix\Bizproc\Validator\validateNumeric
validateNumeric(string $name, int $min=0, int $max=0)
Определения
validator.php:75
Bitrix\Bizproc\Validator\TYPE_STRING
const TYPE_STRING
Определения
validator.php:12
Bitrix\Bizproc\Validator\validate
validate(string $type, $value)
Определения
validator.php:28
Bitrix\Bizproc\Validator\__construct
__construct(array $values)
Определения
validator.php:17
Bitrix\Bizproc\Validator\validateRequire
validateRequire(string $name)
Определения
validator.php:169
Bitrix\Bizproc\Validator\validateEnum
validateEnum(string $name, array $enum)
Определения
validator.php:152
Bitrix\Bizproc\Validator\setPureValue
setPureValue($name)
Определения
validator.php:190
Bitrix\Bizproc\Validator\convertToInt
convertToInt(string $name)
Определения
validator.php:200
Bitrix\Bizproc\Validator\validateRegExp
validateRegExp(string $name, string $pattern)
Определения
validator.php:135
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$name
$name
Определения
menu_edit.php:35
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$val
$val
Определения
options.php:1793
$pattern
if(!Loader::includeModule('sale')) $pattern
Определения
index.php:20
$max
$max
Определения
template_copy.php:262
bitrix
modules
bizproc
lib
validator.php
Создано системой
1.14.0