Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
RegistrationValidator.php
1<?php
2
4
8
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}
static getColors()
Definition color.php:58