WebhookCreateValidation.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Module\OpenAPI\Validations;
  3. use App\Module\OpenAPI\Validators\WebhookUrlValidator;
  4. use App\Module\OpenAPI\Validators\WebhookEventsValidator;
  5. use UCore\ValidationCore;
  6. /**
  7. * Webhook创建验证类
  8. */
  9. class WebhookCreateValidation extends ValidationCore
  10. {
  11. /** @var array|null 处理后的事件列表 */
  12. public ?array $processedEvents = null;
  13. /**
  14. * 验证规则
  15. */
  16. public function rules($rules = []): array
  17. {
  18. return [
  19. // 基础字段验证
  20. ['name', 'required'],
  21. ['name', 'string', 'min' => 2, 'max' => 100],
  22. ['url', 'required'],
  23. ['events', 'required'],
  24. ['timeout', 'integer', 'min' => 1, 'max' => 300],
  25. ['retry_count', 'integer', 'min' => 0, 'max' => 10],
  26. // 业务验证(按顺序执行)
  27. [
  28. 'url', new WebhookUrlValidator($this),
  29. 'msg' => 'Webhook URL无效'
  30. ],
  31. [
  32. 'events', new WebhookEventsValidator($this, ['processedEvents']),
  33. 'msg' => '事件类型配置无效'
  34. ],
  35. ];
  36. }
  37. /**
  38. * 默认值
  39. */
  40. public function default(): array
  41. {
  42. return [
  43. 'timeout' => 30,
  44. 'retry_count' => 3,
  45. 'status' => 'ACTIVE',
  46. ];
  47. }
  48. }