AppService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * 是否记录访问日志
  23. * 建议在当前运行时出错或者需要debug时开启
  24. * @var bool
  25. */
  26. private $enabled = false;
  27. // 服务注册
  28. public function register()
  29. {
  30. }
  31. // 服务启动
  32. public function boot()
  33. {
  34. // 记录访问日志
  35. if ($this->enabled && !is_debug()) {
  36. $log = '';
  37. $log .= $this->getVisitor();
  38. $log .= "\r\n" . '[ header ] ' . print_r(Request::header(), true);
  39. $log .= "" . '[ param ] ' . print_r(Request::param(), true);
  40. $log .= "\r\n" . '--------------------------------------------------------------------------------------------';
  41. Log::record($log, 'begin');
  42. }
  43. }
  44. /**
  45. * 获取请求路径信息
  46. * @return string
  47. */
  48. private function getVisitor()
  49. {
  50. $data = [Request::ip(), Request::method(), Request::url(true)];
  51. return implode(' ', $data);
  52. }
  53. }