PermissionService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CatchAdmin [Just Like ~ ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
  8. // +----------------------------------------------------------------------
  9. // | Author: JaguarJack [ njphper@gmail.com ]
  10. // +----------------------------------------------------------------------
  11. namespace catchAdmin\permissions;
  12. use catchAdmin\permissions\event\OperateLogEvent;
  13. use catchAdmin\permissions\middleware\AuthTokenMiddleware;
  14. use catchAdmin\permissions\middleware\PermissionsMiddleware;
  15. use catchAdmin\permissions\middleware\RecordOperateMiddleware;
  16. use catcher\ModuleService;
  17. class PermissionService extends ModuleService
  18. {
  19. public function register()
  20. {
  21. parent::register(); // TODO: Change the autogenerated stub
  22. $this->registerMiddleWares();
  23. }
  24. public function loadEvents()
  25. {
  26. return [
  27. 'operateLog' => [ OperateLogEvent::class ],
  28. ];
  29. }
  30. public function loadRouteFrom()
  31. {
  32. // TODO: Implement loadRouteFrom() method.
  33. return __DIR__ . DIRECTORY_SEPARATOR . 'route.php';
  34. }
  35. protected function registerMiddleWares()
  36. {
  37. $middleware = $this->app->config->get('middleware');
  38. $middleware['alias']['auth'] = [
  39. AuthTokenMiddleware::class,
  40. PermissionsMiddleware::class,
  41. RecordOperateMiddleware::class
  42. ];
  43. $this->app->config->set($middleware, 'middleware');
  44. }
  45. }