RoleEnum.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Repositories\Enums;
  11. use Illuminate\Support\Str;
  12. use Jiannei\Enum\Laravel\Contracts\LocalizedEnumContract;
  13. use Jiannei\Enum\Laravel\FlaggedEnum;
  14. class RoleEnum extends FlaggedEnum implements LocalizedEnumContract
  15. {
  16. // const GUEST = 1 << 0;
  17. // const ADMIN = 1 << 1;
  18. // const SUPER_ADMIN = self::GUEST | self::ADMIN;
  19. const ADMIN = 'admin';
  20. const TEACHER = 'teacher';
  21. const ADMIN_STUDENT = 'student';
  22. const ADMIN_FACULTY = 'faculty_administrator';
  23. public $name;
  24. public function __construct($flags)
  25. {
  26. parent::__construct($flags);
  27. $this->name = Str::ucfirst(Str::lower(Str::of($this->key)->replace('_', ' ')));
  28. }
  29. public static function makeRoles(): array
  30. {
  31. $rawRoles = self::getInstances();
  32. collect($rawRoles)->each(function ($item, $key) use (&$roles) {
  33. if ($item->value !== self::NONE) {
  34. $roles[] = ['name' => $item->name];
  35. }
  36. });
  37. return $roles;
  38. }
  39. }