Bitrix-D7  20.0.0
main/lib/result.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2015 Bitrix
7  */
8 
9 namespace Bitrix\Main;
10 
12 
13 class Result
14 {
15  /** @var bool */
16  protected $isSuccess = true;
17 
18  /** @var ErrorCollection */
19  protected $errors;
20 
21  /** @var array */
22  protected $data = array();
23 
24  public function __construct()
25  {
26  $this->errors = new ErrorCollection();
27  }
28 
29  /**
30  * Returns the result status.
31  *
32  * @return bool
33  */
34  public function isSuccess()
35  {
36  return $this->isSuccess;
37  }
38 
39  /**
40  * Adds the error.
41  *
42  * @param Error $error
43  * @return $this
44  */
45  public function addError(Error $error)
46  {
47  $this->isSuccess = false;
48  $this->errors[] = $error;
49  return $this;
50  }
51 
52  /**
53  * Returns an array of Error objects.
54  *
55  * @return Error[]
56  */
57  public function getErrors()
58  {
59  return $this->errors->toArray();
60  }
61 
62  /**
63  * Returns the error collection.
64  *
65  * @return ErrorCollection
66  */
67  public function getErrorCollection()
68  {
69  return $this->errors;
70  }
71 
72  /**
73  * Returns array of strings with error messages
74  *
75  * @return array
76  */
77  public function getErrorMessages()
78  {
79  $messages = array();
80 
81  foreach($this->getErrors() as $error)
82  $messages[] = $error->getMessage();
83 
84  return $messages;
85  }
86 
87  /**
88  * Adds array of Error objects
89  *
90  * @param Error[] $errors
91  * @return $this
92  */
93  public function addErrors(array $errors)
94  {
95  $this->isSuccess = false;
96  $this->errors->add($errors);
97  return $this;
98  }
99 
100  /**
101  * Sets data of the result.
102  * @param array $data
103  * @return $this
104  */
105  public function setData(array $data)
106  {
107  // do not save sql expressions
108  foreach ($data as $k => $v)
109  {
110  if ($v instanceof SqlExpression)
111  {
112  unset($data[$k]);
113  }
114  }
115 
116  $this->data = $data;
117 
118  return $this;
119  }
120 
121  /**
122  * Returns data array saved into the result.
123  * @return array
124  */
125  public function getData()
126  {
127  return $this->data;
128  }
129 }
Bitrix\Main\Result\getErrorMessages
getErrorMessages()
Returns array of strings with error messages.
Definition: main/lib/result.php:77
Bitrix\Main\Result\$isSuccess
$isSuccess
Definition: main/lib/result.php:16
Bitrix\Main
Bitrix\Main\DB\SqlExpression
Definition: sqlexpression.php:18
Bitrix\Main\Error
Definition: main/lib/error.php:11
Bitrix\Main\Result\getErrors
getErrors()
Returns an array of Error objects.
Definition: main/lib/result.php:57
Bitrix\Main\ErrorCollection
Definition: main/lib/errorcollection.php:13
Bitrix\Main\Result\__construct
__construct()
Definition: main/lib/result.php:24
Bitrix\Main\Result\setData
setData(array $data)
Sets data of the result.
Definition: main/lib/result.php:105
Bitrix\Main\Result\$errors
$errors
Definition: main/lib/result.php:19
Bitrix\Main\Result\addError
addError(Error $error)
Adds the error.
Definition: main/lib/result.php:45
Bitrix\Main\Result\addErrors
addErrors(array $errors)
Adds array of Error objects.
Definition: main/lib/result.php:93
Bitrix\Main\Result\isSuccess
isSuccess()
Returns the result status.
Definition: main/lib/result.php:34
Bitrix\Main\ORM\Data\Result
Definition: main/lib/orm/data/result.php:15
Bitrix\Main\Result\getData
getData()
Returns data array saved into the result.
Definition: main/lib/result.php:125
Bitrix\Main\ORM\Data\Result\getErrors
getErrors()
Returns an array of Error objects.
Definition: main/lib/orm/data/result.php:67
Bitrix\Main\Result\$data
$data
Definition: main/lib/result.php:22
Bitrix\Main\Result\getErrorCollection
getErrorCollection()
Returns the error collection.
Definition: main/lib/result.php:67