1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
RegistrationValidator.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Im\V2\Marketplace;
4
5
use Bitrix\Im\Color;
6
use Bitrix\Im\V2\Marketplace\Types\Context;
7
use Bitrix\Im\V2\Marketplace\Types\Role;
8
9
class
RegistrationValidator
10
{
11
private
array
$result;
12
private
array
$placementBind;
13
14
15
public
static
function
init
(
array
$placementBind): self
16
{
17
return
new
static
($placementBind);
18
}
19
23
public
function
__construct
(
array
$placementBind)
24
{
25
$this->result = [
26
'error'
=>
null
,
27
'error_description'
=>
null
,
28
];
29
30
$this->placementBind = $placementBind;
31
}
32
36
public
function
getResult
():
array
37
{
38
return
$this->result
;
39
}
40
44
public
function
validateIconName
(): self
45
{
46
if
(!isset($this->placementBind[
'OPTIONS'
][
'iconName'
]))
47
{
48
$this->result[
'error'
] =
'EMPTY_ERROR_ICON_NAME'
;
49
$this->result[
'error_description'
] =
'Field iconName is empty.'
;
50
51
return
$this;
52
}
53
54
if
(mb_strlen($this->placementBind[
'OPTIONS'
][
'iconName'
]) > 50)
55
{
56
$this->result[
'error'
] =
'INVALID_ERROR_ICON_NAME'
;
57
$this->result[
'error_description'
] =
'Field iconName is invalid.'
;
58
59
return
$this;
60
}
61
62
if
(!preg_match(
'/[a-zA-Z \-]/'
, $this->placementBind[
'OPTIONS'
][
'iconName'
]))
63
{
64
$this->result[
'error'
] =
'INVALID_ERROR_ICON_NAME'
;
65
$this->result[
'error_description'
] =
'Field iconName is invalid.'
;
66
67
return
$this;
68
}
69
70
return
$this;
71
}
72
76
public
function
validateExtranet
(): self
77
{
78
if
($this->placementBind[
'OPTIONS'
][
'extranet'
] !==
'N'
&& $this->placementBind[
'OPTIONS'
][
'extranet'
] !==
'Y'
)
79
{
80
$this->result[
'error'
] =
'INVALID_ERROR_EXTRANET'
;
81
$this->result[
'error_description'
] =
'Field extranet is invalid.'
;
82
83
return
$this;
84
}
85
86
return
$this;
87
}
88
92
public
function
validateContext
(): self
93
{
94
$userRawContext = $this->placementBind[
'OPTIONS'
][
'context'
];
95
$userContextList = explode(
';'
, trim($userRawContext));
96
foreach
($userContextList as
$context
)
97
{
98
if
(!in_array(
$context
, Context::getTypes(),
true
))
99
{
100
$this->result[
'error'
] =
'INVALID_ERROR_CONTEXT'
;
101
$this->result[
'error_description'
] =
'Field context is invalid.'
;
102
103
return
$this;
104
}
105
}
106
107
return
$this;
108
}
109
113
public
function
validateRole
(): self
114
{
115
if
(!in_array($this->placementBind[
'OPTIONS'
][
'role'
], Role::getTypes(),
true
))
116
{
117
$this->result[
'error'
] =
'INVALID_ERROR_ROLE'
;
118
$this->result[
'error_description'
] =
'Field role is invalid.'
;
119
}
120
121
return
$this;
122
}
123
124
public
function
validateColor
(): self
125
{
126
if
(
127
$this->placementBind[
'OPTIONS'
][
'color'
] !==
''
128
&& !array_key_exists($this->placementBind[
'OPTIONS'
][
'color'
],
Color::getColors
())
129
)
130
{
131
$this->result[
'error'
] =
'INVALID_ERROR_COLOR'
;
132
$this->result[
'error_description'
] =
'Field color is invalid.'
;
133
}
134
135
return
$this;
136
}
137
138
public
function
validateHeight
(): self
139
{
140
if
($this->placementBind[
'OPTIONS'
][
'height'
] < 0)
141
{
142
$this->result[
'error'
] =
'INVALID_ERROR_HEIGHT'
;
143
$this->result[
'error_description'
] =
'Field height is invalid.'
;
144
}
145
146
return
$this;
147
}
148
149
public
function
validateWidth
(): self
150
{
151
if
($this->placementBind[
'OPTIONS'
][
'width'
] < 0)
152
{
153
$this->result[
'error'
] =
'INVALID_ERROR_WIDTH'
;
154
$this->result[
'error_description'
] =
'Field width is invalid.'
;
155
}
156
157
return
$this;
158
}
159
160
}
Bitrix\Im\Color\getColors
static getColors()
Определения
color.php:58
Bitrix\Im\V2\Marketplace\RegistrationValidator
Определения
RegistrationValidator.php:10
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateRole
validateRole()
Определения
RegistrationValidator.php:113
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateExtranet
validateExtranet()
Определения
RegistrationValidator.php:76
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateContext
validateContext()
Определения
RegistrationValidator.php:92
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateWidth
validateWidth()
Определения
RegistrationValidator.php:149
Bitrix\Im\V2\Marketplace\RegistrationValidator\__construct
__construct(array $placementBind)
Определения
RegistrationValidator.php:23
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateHeight
validateHeight()
Определения
RegistrationValidator.php:138
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateIconName
validateIconName()
Определения
RegistrationValidator.php:44
Bitrix\Im\V2\Marketplace\RegistrationValidator\validateColor
validateColor()
Определения
RegistrationValidator.php:124
Bitrix\Im\V2\Marketplace\RegistrationValidator\init
static init(array $placementBind)
Определения
RegistrationValidator.php:15
Bitrix\Im\V2\Marketplace\RegistrationValidator\getResult
getResult()
Определения
RegistrationValidator.php:36
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$context
$context
Определения
csv_new_setup.php:223
bitrix
modules
im
lib
V2
Marketplace
RegistrationValidator.php
Создано системой
1.14.0