1 | <?php declare(strict_types=1); |
||
29 | final class BlockReplies |
||
30 | { |
||
31 | /** |
||
32 | * Rule reply key. |
||
33 | */ |
||
34 | private const REPLY_SUCCESS_VALUE = 0; |
||
35 | |||
36 | /** |
||
37 | * Rule reply key. |
||
38 | */ |
||
39 | private const REPLY_ERRORS_INFO = self::REPLY_SUCCESS_VALUE + 1; |
||
40 | |||
41 | /** |
||
42 | * Error info key. |
||
43 | */ |
||
44 | public const ERROR_INFO_BLOCK_INDEX = 0; |
||
45 | |||
46 | /** |
||
47 | * Error info key. |
||
48 | */ |
||
49 | public const ERROR_INFO_VALUE = self::ERROR_INFO_BLOCK_INDEX + 1; |
||
50 | |||
51 | /** |
||
52 | * Error info key. |
||
53 | */ |
||
54 | public const ERROR_INFO_CODE = self::ERROR_INFO_VALUE + 1; |
||
55 | |||
56 | /** |
||
57 | * Error info key. |
||
58 | */ |
||
59 | public const ERROR_INFO_MESSAGE_TEMPLATE = self::ERROR_INFO_CODE + 1; |
||
60 | |||
61 | /** |
||
62 | * Error info key. |
||
63 | */ |
||
64 | public const ERROR_INFO_MESSAGE_PARAMETERS = self::ERROR_INFO_MESSAGE_TEMPLATE + 1; |
||
65 | |||
66 | /** |
||
67 | * @param mixed $result |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 19 | public static function createSuccessReply($result): array |
|
78 | |||
79 | /** |
||
80 | * @return array |
||
81 | */ |
||
82 | 3 | public static function createStartSuccessReply(): array |
|
86 | |||
87 | /** |
||
88 | * @return array |
||
89 | */ |
||
90 | 4 | public static function createEndSuccessReply(): array |
|
94 | |||
95 | /** |
||
96 | * @param ContextInterface $context |
||
97 | * @param mixed $errorValue |
||
98 | * @param int $errorCode |
||
99 | * @param string $messageTemplate |
||
100 | * @param array $messageParams |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | 14 | public static function createErrorReply( |
|
124 | |||
125 | /** |
||
126 | * @param ContextInterface $context |
||
127 | * @param int $errorCode |
||
128 | * @param string $messageTemplate |
||
129 | * @param array $messageParams |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 2 | public static function createStartErrorReply( |
|
134 | ContextInterface $context, |
||
135 | int $errorCode, |
||
136 | string $messageTemplate, |
||
137 | array $messageParams |
||
138 | ): array { |
||
139 | 2 | $value = null; |
|
140 | |||
141 | return [ |
||
142 | 2 | static::createErrorInfoEntry( |
|
143 | 2 | $context->getCurrentBlockId(), |
|
144 | 2 | $value, |
|
145 | 2 | $errorCode, |
|
146 | 2 | $messageTemplate, |
|
147 | 2 | $messageParams |
|
148 | ), |
||
149 | ]; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param ContextInterface $context |
||
154 | * @param int $errorCode |
||
155 | * @param string $messageTemplate |
||
156 | * @param array $messageParams |
||
157 | * |
||
158 | * @return array |
||
159 | */ |
||
160 | 3 | public static function createEndErrorReply( |
|
161 | ContextInterface $context, |
||
162 | int $errorCode, |
||
163 | string $messageTemplate, |
||
164 | array $messageParams |
||
165 | ): array { |
||
166 | 3 | $value = null; |
|
167 | |||
168 | return [ |
||
169 | 3 | static::createErrorInfoEntry( |
|
170 | 3 | $context->getCurrentBlockId(), |
|
171 | 3 | $value, |
|
172 | 3 | $errorCode, |
|
173 | 3 | $messageTemplate, |
|
174 | 3 | $messageParams |
|
175 | ), |
||
176 | ]; |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @param int $blockId |
||
181 | * @param mixed $value |
||
182 | * @param int $code |
||
183 | * @param string $messageTemplate |
||
184 | * @param array $messageParams |
||
185 | * |
||
186 | * @return array |
||
187 | */ |
||
188 | 17 | protected static function createErrorInfoEntry( |
|
203 | |||
204 | /** |
||
205 | * @param array $result |
||
206 | * |
||
207 | * @return bool |
||
208 | */ |
||
209 | 21 | public static function isResultSuccessful(array $result): bool |
|
221 | |||
222 | /** |
||
223 | * @param array $result |
||
224 | * |
||
225 | * @return mixed |
||
226 | */ |
||
227 | 19 | public static function extractResultOutput(array $result) |
|
236 | |||
237 | /** |
||
238 | * @param array $result |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | 14 | public static function extractResultErrorsInfo(array $result): array |
|
255 | } |
||
256 |