AppService.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace cores;
  13. use think\Service;
  14. use think\facade\Log;
  15. use think\facade\Request;
  16. /**
  17. * 应用服务类
  18. */
  19. class AppService extends Service
  20. {
  21. // 服务注册
  22. public function register()
  23. {
  24. }
  25. // 服务启动
  26. public function boot()
  27. {
  28. // 记录访问日志
  29. if (env('access_log') && !is_debug()) {
  30. $log = $this->getVisitor();
  31. $log .= "\r\n" . '[ header ] ' . print_r(Request::header(), true);
  32. $log .= "" . '[ param ] ' . print_r(Request::param(), true);
  33. $log .= "\r\n" . '--------------------------------------------------------------------------------------------';
  34. Log::record($log, 'begin');
  35. }
  36. }
  37. /**
  38. * 获取请求路径信息
  39. * @return string
  40. */
  41. private function getVisitor(): string
  42. {
  43. $data = [Request::ip(), Request::method(), Request::url(true)];
  44. return implode(' ', $data);
  45. }
  46. }