File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 "ext-pdo" : " *" ,
1919 "psr/simple-cache" : " >=1.0" ,
2020 "psr/log" : " >=1.0" ,
21- "topthink/think-helper" :" ^3.1"
21+ "topthink/think-helper" :" ^3.1" ,
22+ "topthink/think-validate" :" ^3.0"
2223 },
2324 "require-dev" : {
2425 "phpunit/phpunit" : " ^9.6|^10"
Original file line number Diff line number Diff line change 1515
1616use ArrayAccess ;
1717use Closure ;
18- use InvalidArgumentException ;
1918use JsonSerializable ;
2019use think \contract \Arrayable ;
2120use think \contract \Jsonable ;
@@ -320,21 +319,16 @@ protected function parseValidate(): string
320319 * @param array $data 数据
321320 * @param array $allow 需要验证的字段
322321 *
323- * @throws InvalidArgumentException
322+ * @throws ValidateException
324323 * @return void
325324 */
326325 protected function validate (array $ data , array $ allow = []): void
327326 {
328327 $ validater = $ this ->getOption ('validate ' );
329- if (!empty ($ validater ) && class_exists ('think\validate ' )) {
330- try {
331- validate ($ validater )
332- ->only ($ allow ?: array_keys ($ data ))
333- ->check ($ data );
334- } catch (ValidateException $ e ) {
335- // 验证失败 输出错误信息
336- throw new InvalidArgumentException ($ e ->getError ());
337- }
328+ if (!empty ($ validater )) {
329+ validate ($ validater )
330+ ->only ($ allow ?: array_keys ($ data ))
331+ ->check ($ data );
338332 }
339333 }
340334
Original file line number Diff line number Diff line change 1313
1414namespace think \model ;
1515
16- use InvalidArgumentException ;
1716use ReflectionClass ;
1817use ReflectionProperty ;
1918use think \Entity ;
@@ -324,23 +323,19 @@ protected function convertData(): array
324323 * @param array $data 数据
325324 * @param array $allow 需要验证的字段
326325 *
327- * @throws InvalidArgumentException
326+ * @throws ValidateException
328327 * @return array
329328 */
330329 protected function validate (array $ data = [], array $ allow = []): array
331330 {
332331 $ validater = $ this ->getOption ('validate ' );
333- if (!empty ($ validater ) && class_exists ('think\validate ' )) {
334- $ data = $ data ?: $ this ->getData ();
335- try {
336- return validate ($ validater )
337- ->only ($ allow ?: array_keys ($ data ))
338- ->checked ($ data );
339- } catch (ValidateException $ e ) {
340- // 验证失败 输出错误信息
341- throw new InvalidArgumentException ($ e ->getError ());
342- }
332+ $ data = $ data ?: $ this ->getData ();
333+ if (!empty ($ validater )) {
334+ return validate ($ validater )
335+ ->only ($ allow ?: array_keys ($ data ))
336+ ->checked ($ data );
343337 }
338+ return $ data ;
344339 }
345340
346341 /**
You can’t perform that action at this time.
0 commit comments