ApiValidate.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\admin\validate\sys_manage;
  3. use support\Validate;
  4. class ApiValidate extends Validate
  5. {
  6. protected $rule = [
  7. 'api_id' => 'require|alphaDash',
  8. 'api_status|状态' => 'require|in:ACTIVED,DISABLED',
  9. 'api_category|分类' => 'max:32',
  10. 'api_token|Token' => 'max:32',
  11. 'api_name|名称' => 'max:64',
  12. 'api_request_json|请求体配置' => 'isJson',
  13. 'api_response_json|应答体配置' => 'isJson'
  14. ];
  15. protected $scene = [
  16. 'add' => ['api_status', 'api_category', 'api_token', 'api_name', 'api_request_json', 'api_response_json'],
  17. 'update' => ['api_id', 'api_status', 'api_category', 'api_token', 'api_name', 'api_request_json', 'api_response_json'],
  18. ];
  19. /**
  20. * @Desc 验证Json
  21. * @Author Gorden
  22. * @Date 2024/4/1 13:51
  23. *
  24. * @param $value
  25. * @return string|true
  26. */
  27. public function isJson($value)
  28. {
  29. if (is_json($value)) {
  30. return true;
  31. }
  32. return "数据格式错误";
  33. }
  34. }