| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Module\OpenAPI\Validations;
- use App\Module\OpenAPI\Validators\WebhookUrlValidator;
- use App\Module\OpenAPI\Validators\WebhookEventsValidator;
- use UCore\ValidationCore;
- /**
- * Webhook更新验证类
- */
- class WebhookUpdateValidation extends ValidationCore
- {
- /** @var array|null 处理后的事件列表 */
- public ?array $processedEvents = null;
- /**
- * 验证规则
- */
- public function rules($rules = []): array
- {
- return [
- // 基础字段验证(可选)
- ['name', 'string', 'min' => 2, 'max' => 100, 'when' => function($data) {
- return isset($data['name']);
- }],
- ['status', 'in', 'range' => ['ACTIVE', 'INACTIVE'], 'when' => function($data) {
- return isset($data['status']);
- }],
- ['timeout', 'integer', 'min' => 1, 'max' => 300, 'when' => function($data) {
- return isset($data['timeout']);
- }],
- ['retry_count', 'integer', 'min' => 0, 'max' => 10, 'when' => function($data) {
- return isset($data['retry_count']);
- }],
- // 业务验证(按顺序执行)
- [
- 'url', new WebhookUrlValidator($this),
- 'msg' => 'Webhook URL无效',
- 'when' => function($data) {
- return isset($data['url']) && !empty($data['url']);
- }
- ],
- [
- 'events', new WebhookEventsValidator($this, ['processedEvents']),
- 'msg' => '事件类型配置无效',
- 'when' => function($data) {
- return isset($data['events']);
- }
- ],
- ];
- }
- /**
- * 默认值
- */
- public function default(): array
- {
- return [];
- }
- }
|