CommonValidate.php 480 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace app\validate;
  3. use think\facade\Request;
  4. use think\Validate;
  5. class CommonValidate extends Validate
  6. {
  7. protected $request;
  8. public function __construct(Request $request)
  9. {
  10. $this->request = $request;
  11. parent::__construct();
  12. }
  13. // 自定义验证规则:验证是否为有效的JSON格式
  14. protected function isJson($value): bool
  15. {
  16. json_decode($value);
  17. return (json_last_error() == JSON_ERROR_NONE);
  18. }
  19. }