Permission.php 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace plugin\saiadmin\service;
  3. /**
  4. * 权限注解
  5. */
  6. #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
  7. class Permission
  8. {
  9. /**
  10. * 权限标题/名称
  11. */
  12. public string $title;
  13. /**
  14. * 权限标识(唯一,格式如:module:controller:action)
  15. */
  16. public ?string $slug = null;
  17. /**
  18. * 构造函数 #[Permission(title:'标题', slug:'标识')]
  19. * @param string|null $title
  20. * @param string|null $slug
  21. */
  22. public function __construct(
  23. ?string $title = null,
  24. ?string $slug = null,
  25. )
  26. {
  27. $this->title = $title ?? '';
  28. $this->slug = $slug;
  29. }
  30. /**
  31. * 获取权限标题
  32. */
  33. public function getTitle(): string
  34. {
  35. return $this->title;
  36. }
  37. /**
  38. * 获取权限标识
  39. */
  40. public function getSlug(): ?string
  41. {
  42. return $this->slug;
  43. }
  44. }