php 验证所传参数为必填的时候的验证逻辑

此段代码摘自lumen框架: xx/vendor/illuminate/validation/Validator.php
/** * Validate that a required attribute exists. * * @param string $attribute * @param mixed $value * @return bool */ protected function validateRequired($attribute, $value) { if (is_null($value)) { return false; } elseif (is_string($value) && trim($value) === '') { return false; } elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) { return false; } elseif ($value instanceof File) { return (string) $value->getPath() != ''; } return true; }

 

posted on 2016-04-05 14:08  mingaixin  阅读(913)  评论(0编辑  收藏  举报