Update Core\Validator

Change the getData() method to be able to exclude the specified elements.
This commit is contained in:
Visman 2021-01-19 00:48:41 +07:00
parent 21e1e40e0e
commit e0b08758f1

View file

@ -405,16 +405,22 @@ class Validator
* Возвращает проверенные данные
* Поля с ошибками содержат значения по умолчанию или значения с ошибками
*/
public function getData(bool $all = false): array
public function getData(bool $all = false, array $doNotUse = null): array
{
if (empty($this->status)) {
throw new RuntimeException('Data not found');
}
if ($all) {
return $this->result;
if (null === $doNotUse) {
$result = $this->result;
} else {
return \array_filter($this->result, function ($value) {
$result = \array_diff_key($this->result, \array_flip($doNotUse));
}
if ($all) {
return $result;
} else {
return \array_filter($result, function ($value) {
return null !== $value;
});
}