VideoTemplate.php 997 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Services\Markup\Templates;
  3. use App\Services\Markup\Html\HtmlPolicy;
  4. use App\Services\Markup\Ir\Call;
  5. use App\Services\Markup\Render\RenderContext;
  6. /**
  7. * 视频:`{{v|url|style|title}}`。style 缺省 modal。地址只允许 http(s) 与站内路径。
  8. */
  9. final class VideoTemplate extends Template
  10. {
  11. protected string $component = 'video';
  12. public function params(): array
  13. {
  14. return ['url' => ParamSpec::at(1), 'style' => ParamSpec::at(2, 'modal'), 'title' => ParamSpec::at(3)];
  15. }
  16. /**
  17. * @return array<string, mixed>
  18. */
  19. public function props(Call $call, RenderContext $ctx): array
  20. {
  21. return [
  22. 'url' => HtmlPolicy::url((string) $call->param('url')) ?? '',
  23. 'title' => (string) $call->param('title'),
  24. 'style' => (string) $call->param('style'),
  25. ];
  26. }
  27. public function text(Call $call, RenderContext $ctx): string
  28. {
  29. return (string) $call->param('title');
  30. }
  31. }