AppServiceProvider.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\common\providers;
  3. use App;
  4. use app\common\facades\RichText;
  5. use app\common\models\AccountWechats;
  6. use app\common\modules\site\SiteSetting;
  7. use app\common\modules\site\SiteSettingCache;
  8. use app\common\modules\site\WqUniSetting;
  9. use app\common\repositories\OptionRepository;
  10. use app\common\services\mews\captcha\src\Captcha;
  11. use app\framework\Log\CronLog;
  12. use app\framework\Log\SqlLog;
  13. use app\framework\Log\TraceLog;
  14. use app\common\facades\Setting;
  15. use app\platform\Repository\SystemSetting;
  16. use Illuminate\Database\Events\StatementPrepared;
  17. use Illuminate\Support\Facades\Cookie;
  18. use Illuminate\Support\ServiceProvider;
  19. use app\common\services\Utils;
  20. use Illuminate\Support\Facades\DB;
  21. class AppServiceProvider extends ServiceProvider
  22. {
  23. /**
  24. * Bootstrap any application services.
  25. *
  26. * @return void
  27. */
  28. public function boot()
  29. {
  30. //安装验证
  31. $this->verifyInstall();
  32. \Cron::setDisablePreventOverlapping();
  33. \Cron::setLogger((new CronLog())->getLogger()->getLogger());
  34. \Event::listen(StatementPrepared::class, function ($event) {
  35. $event->statement->setFetchMode(\PDO::FETCH_ASSOC);
  36. });
  37. $preg_arr = [
  38. '/\/business\/(.*?)\//',
  39. '/\/andaCallback\/(.*?)\//',
  40. '/\/eplusCallback\/(.*?)\//',
  41. '/\/outside\/(.*?)\//',
  42. ];
  43. foreach ($preg_arr as $v){
  44. preg_match($v,request()->getRequestUri(),$match);
  45. if ($match[1]) {
  46. request()->offsetSet('i',$match[1]);
  47. break;
  48. }
  49. }
  50. //$preg = '/\/business\/(.*?)\//';
  51. // preg_match($preg,request()->getRequestUri(),$match);
  52. // if ($match[1]) {
  53. // request()->offsetSet('i',$match[1]);
  54. // }
  55. }
  56. /**
  57. * Register any application services.
  58. *
  59. * @return void
  60. */
  61. public function register()
  62. {
  63. //微信接口不输出错误
  64. if (strpos(request()->getRequestUri(), '/api.php') >= 0) {
  65. error_reporting(0);
  66. }
  67. // if ($this->app->environment() !== 'production') {
  68. // $this->app->register(\Orangehill\Iseed\IseedServiceProvider::class);
  69. // $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
  70. //
  71. // DB::listen(function ($sql) {
  72. // foreach ($sql->bindings as $i => $binding) {
  73. // if ($binding instanceof \DateTime) {
  74. // $sql->bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
  75. // } else {
  76. // if (is_string($binding)) {
  77. // $sql->bindings[$i] = "'$binding'";
  78. // }
  79. // }
  80. // }
  81. // // Insert bindings into query
  82. // $query = str_replace(array('%', '?'), array('%%', '%s'), $sql->sql);
  83. // $query = vsprintf($query, $sql->bindings);
  84. // // Save the query to file
  85. // (new SqlLog())->getLogger()->getLogger()->addInfo($query);;
  86. // });
  87. // }
  88. //增加模板扩展tpl
  89. \View::addExtension('tpl', 'blade');
  90. //配置表
  91. $this->app->singleton('options', OptionRepository::class);
  92. $this->app->singleton('siteSetting', SiteSetting::class);
  93. $this->app->singleton('siteSettingCache', SiteSettingCache::class);
  94. $this->app->singleton('SystemSetting', SystemSetting::class);
  95. $this->app->singleton('WqUniSetting', WqUniSetting::class);
  96. /**
  97. * 设置
  98. */
  99. $this->app->bind('setting', function() {
  100. return new Setting();
  101. });
  102. $this->app->bind('captcha', Captcha::class);
  103. $this->app->singleton('Log.trace', function () {
  104. return new TraceLog();
  105. });
  106. }
  107. private function verifyInstall()
  108. {
  109. if (config('app.framework') == 'platform' && !file_exists(base_path().'/bootstrap/install.lock') && !strpos(request()->path(), 'install')) {
  110. response()->json([
  111. 'result' => 0,
  112. 'msg' => '',
  113. 'data' => ['status' => -4]
  114. ], 200, ['charset' => 'utf-8'])->send();
  115. exit;
  116. }
  117. }
  118. }