Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
objectstatus.php
1<?php
3
9{
11 private $errors = [];
12
16 public function isSuccess(): bool
17 {
18 return empty($this->errors);
19 }
20
24 public function hasErrors(): bool
25 {
26 return !$this->isSuccess();
27 }
28
34 public function addError(string $code, string $message)
35 {
36 $this->errors[] = [
37 'code' => $code,
38 'message' => $message,
39 ];
40 }
41
45 public function resetErrors()
46 {
47 $this->errors = [];
48 }
49
53 public function getErrors(): array
54 {
55 return $this->errors;
56 }
57
62 public function getErrorsByCode(string $code): array
63 {
64 if(!$this->hasErrors()) {
65 return [];
66 }
67
68 return array_filter($this->errors, function($error) use ($code)
69 {
70 return $error['code'] == $code;
71 });
72 }
73
78 public function getErrorByCode(string $code): array
79 {
80 if($filtredErrors = $this->getErrorsByCode($code))
81 {
82 return end($filtredErrors);
83 }
84
85 return [];
86 }
87}
addError(string $code, string $message)