ViewInit.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\middleware;
  12. use app\admin\service\ConfigService;
  13. use app\common\constants\AdminConstant;
  14. use think\App;
  15. use think\facade\Request;
  16. use think\facade\View;
  17. /**
  18. * @deprecated 废弃,新版TP不支持在中间件获取控制器相关信息
  19. * Class ViewInit
  20. * @package app\admin\middleware
  21. */
  22. class ViewInit
  23. {
  24. public function handle(\app\Request $request, \Closure $next)
  25. {
  26. list($thisModule, $thisController, $thisAction) = [app('http')->getName(), Request::controller(), $request->action()];
  27. list($thisControllerArr, $jsPath) = [explode('.', $thisController), null];
  28. foreach ($thisControllerArr as $vo) {
  29. empty($jsPath) ? $jsPath = parse_name($vo) : $jsPath .= '/' . parse_name($vo);
  30. }
  31. $autoloadJs = file_exists(root_path('public')."static/{$thisModule}/js/{$jsPath}.js") ? true : false;
  32. $thisControllerJsPath = "{$thisModule}/js/{$jsPath}.js";
  33. $adminModuleName = config('app.admin_alias_name');
  34. $isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID ? true : false;
  35. $data = [
  36. 'adminModuleName' => $adminModuleName,
  37. 'thisController' => parse_name($thisController),
  38. 'thisAction' => $thisAction,
  39. 'thisRequest' => parse_name("{$thisModule}/{$thisController}/{$thisAction}"),
  40. 'thisControllerJsPath' => "{$thisControllerJsPath}",
  41. 'autoloadJs' => $autoloadJs,
  42. 'isSuperAdmin' => $isSuperAdmin,
  43. 'version' => env('app_debug') ? time() : ConfigService::getVersion(),
  44. ];
  45. View::assign($data);
  46. $request->adminModuleName = $adminModuleName;
  47. return $next($request);
  48. }
  49. }