PermissionResourceCommand.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Command;
  4. use App\Repositories\Utils\AccessControllerListsRepository;
  5. use Hyperf\Command\Command as HyperfCommand;
  6. use Hyperf\Command\Annotation\Command;
  7. use Psr\Container\ContainerInterface;
  8. /**
  9. * @Command
  10. */
  11. class PermissionResourceCommand extends HyperfCommand
  12. {
  13. /**
  14. * @var ContainerInterface
  15. */
  16. protected $container;
  17. protected $name = 'permission:resource';
  18. /**
  19. * 属性描述.
  20. *
  21. * @var AccessControllerListsRepository
  22. */
  23. private $aclRepo = null;
  24. public function __construct(ContainerInterface $container)
  25. {
  26. $this->container = $container;
  27. parent::__construct($this->name);
  28. }
  29. public function configure()
  30. {
  31. parent::configure();
  32. $this->setDescription('更新后台权限资源表');
  33. }
  34. public function handle()
  35. {
  36. $authConfig = config('manage_acl');
  37. $this->getAclRepo()->getController(
  38. $authConfig,
  39. base_path(). '/Modules/Manage/Controllers',
  40. 'Controller',
  41. 'Modules\Manage\Controllers'
  42. );
  43. $this->line('更新权限资源完毕,可以去表[permission_resource]查看确认', 'info');
  44. }
  45. /**
  46. * 获取ACL仓库
  47. * @return AccessControllerListsRepository|null
  48. */
  49. private function getAclRepo()
  50. {
  51. if (empty($this->aclRepo)) {
  52. $this->aclRepo = make(AccessControllerListsRepository::class);
  53. }
  54. return $this->aclRepo;
  55. }
  56. }