Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
objectstatus.php
1<?php
3
9{
11 private array $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 {
66 return [];
67 }
68
69 return array_filter($this->errors, static function($error) use ($code)
70 {
71 return $error['code'] == $code;
72 });
73 }
74
79 public function getErrorByCode(string $code): array
80 {
81 if ($filteredErrors = $this->getErrorsByCode($code))
82 {
83 return end($filteredErrors);
84 }
85
86 return [];
87 }
88}