Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
errorscontainer.php
1<?php
3
6
7final class ErrorsContainer extends Result
8{
9 protected $acceptableErrorCodes = [];
10
15 public function addError(Error $error)
16 {
17 if(!$this->isErrorAcceptable($error))
18 {
19 parent::addError($error);
20 }
21 }
22
29 public function addErrors(array $errors)
30 {
31 if(!empty($this->acceptableErrorCodes))
32 {
33 $errorsToAdd = array();
34
35 foreach($errors as $error)
36 {
37 if(!$this->isErrorAcceptable($error))
38 {
39 $errorsToAdd[] = $error;
40 }
41 }
42
43 $this->errors->add($errorsToAdd);
44 }
45 else
46 {
47 $this->errors->add($errors);
48 }
49 return $this;
50 }
51
52 public function setAcceptableErrorCodes(array $errorCodes)
53 {
54 $this->acceptableErrorCodes = $errorCodes;
55 }
56
57 private function isErrorAcceptable(Error $error)
58 {
59 if(empty($this->acceptableErrorCodes))
60 {
61 return false;
62 }
63
64 $code = $error->getCode();
65
66 if(empty($code))
67 {
68 return false;
69 }
70
71 return in_array($code, $this->acceptableErrorCodes);
72 }
73}