ShowTermRequest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. /**
  5. * `GET /v3/terms/{term}`:正文按哪些 channel 渲染、read / edit 模式、节点树或 HTML(都可选)。
  6. */
  7. class ShowTermRequest extends FormRequest
  8. {
  9. public function authorize(): bool
  10. {
  11. return true;
  12. }
  13. /**
  14. * @return array<string, array<int, mixed>>
  15. */
  16. public function rules(): array
  17. {
  18. return [
  19. 'channels' => ['sometimes', 'string', 'max:1024', 'regex:/^[0-9a-fA-F-]{36}(,[0-9a-fA-F-]{36}){0,19}$/'],
  20. 'mode' => ['sometimes', 'in:read,edit'],
  21. 'format' => ['sometimes', 'in:tree,html'],
  22. ];
  23. }
  24. /**
  25. * @return array{channels?: list<string>, mode?: string, format?: string}
  26. */
  27. public function render(): array
  28. {
  29. $data = $this->validated();
  30. if (isset($data['channels'])) {
  31. $data['channels'] = array_values(array_unique(explode(',', $data['channels'])));
  32. }
  33. return $data;
  34. }
  35. }