CheckDemoMiddleware.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. declare (strict_types=1);
  15. namespace app\adminapi\http\middleware;
  16. use app\common\service\JsonService;
  17. /**
  18. * 校验演示环境
  19. * Class CheckDemoMiddleware
  20. * @package app\adminapi\http\middleware
  21. */
  22. class CheckDemoMiddleware
  23. {
  24. // 允许post的接口
  25. protected $ablePost = [
  26. 'login/account',
  27. 'login/logout',
  28. ];
  29. public function handle($request, \Closure $next)
  30. {
  31. if ($request->method() != 'POST') {
  32. return $next($request);
  33. }
  34. $accessUri = strtolower($request->controller() . '/' . $request->action());
  35. if (!in_array($accessUri, $this->ablePost) && env('project.demo_env')) {
  36. return JsonService::fail('演示环境不支持修改数据,请下载源码本地部署体验');
  37. }
  38. return $next($request);
  39. }
  40. }