Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/4/3 0003
|
||||
* Time: 15:28
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace validator;
|
||||
|
||||
|
||||
/**
|
||||
* Class ArrayValidator
|
||||
* @package validator
|
||||
*/
|
||||
class ArrayValidator extends BaseValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* 检查
|
||||
*/
|
||||
public function trigger(): bool
|
||||
{
|
||||
if (empty($this->params)) {
|
||||
return true;
|
||||
}
|
||||
if (!isset($this->params[$this->field])) {
|
||||
return true;
|
||||
}
|
||||
if (!is_array($this->params[$this->field])) {
|
||||
return $this->addError("The param :attribute must a array");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
*
|
||||
* 转成数组
|
||||
*/
|
||||
private function toArray($data): array
|
||||
{
|
||||
if (is_numeric($data)) {
|
||||
return [];
|
||||
} else if (is_null(json_decode($data, true))) {
|
||||
return [];
|
||||
} elseif (is_object($data)) {
|
||||
$data = get_object_vars($data);
|
||||
}
|
||||
|
||||
$_tmp = [];
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_object($val)) {
|
||||
$_tmp[$key] = $this->toArray($val);
|
||||
} else if (is_array($val)) {
|
||||
$_tmp[$key] = $this->toArray($val);
|
||||
} else {
|
||||
$_tmp[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $_tmp;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user