ActionUtil.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Utils\Control;
  3. class ActionUtil{
  4. protected array $actions = [];// 控制器信息
  5. protected static $instance;
  6. public static function getInstance(): ActionUtil
  7. {
  8. if (empty(self::$instance)) {
  9. self::$instance = new self();
  10. }
  11. return self::$instance;
  12. }
  13. /**
  14. * 获取当前路由地址
  15. * @return array
  16. */
  17. public function actions(){
  18. $action = request()->route()->getAction();
  19. $actions = str_replace($action['namespace'].'\\','',!empty($action['controller'])?$action['controller']:'');
  20. $actions = str_replace('\\','/',$actions);
  21. if (!empty($actions)){
  22. $action = explode('@',$actions);
  23. $this->actions['controller'] = !empty($action[0])?$action[0]:'CommonController.php';
  24. $this->actions['action'] = !empty($action[1])?$action[1]:'common';
  25. }else{
  26. $this->actions['controller'] = 'CommonController.php';
  27. $this->actions['action'] = 'common';
  28. }
  29. return $this->actions;
  30. }
  31. public function get()
  32. {
  33. return $this->actions;
  34. }
  35. }