RoleEnum.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. public $name;
  20. public function __construct($flags)
  21. {
  22. parent::__construct($flags);
  23. $this->name = Str::ucfirst(Str::lower(Str::of($this->key)->replace('_', ' ')));
  24. }
  25. public static function makeRoles(): array
  26. {
  27. $rawRoles = self::getInstances();
  28. collect($rawRoles)->each(function ($item, $key) use (&$roles) {
  29. if ($item->value !== self::NONE) {
  30. $roles[] = ['name' => $item->name];
  31. }
  32. });
  33. return $roles;
  34. }
  35. }