AppServiceProvider.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Providers;
  3. use App\Exceptions\ParameterException;
  4. use App\Foundation\ElasticsearchClient;
  5. use App\Helpers\File;
  6. use App\Helpers\Utils;
  7. use App\Helpers\DataConverter;
  8. use App\Services\CallApiService;
  9. use Illuminate\Support\Facades\View;
  10. use Illuminate\Support\ServiceProvider;
  11. use Illuminate\Pagination\Paginator;
  12. class AppServiceProvider extends ServiceProvider
  13. {
  14. private $whiteList = ['front.dabory.erp.list-type.type1', 'front.dabory.erp.list-type.genesis-type1', 'front.dabory.pro.my-app.list-type.type1', 'front.dabory.erp.list-type.list-media1',
  15. 'front.dabory.erp.list-type.setup-type1', 'front.dabory.erp.list-type.struct-type1', 'front.dabory.erp.list-type.search-type1', 'front.dabory.erp.list-type.cal-type1', 'msg.dabory.pro.*',];
  16. /**
  17. * Register any application services.
  18. *
  19. * @return void
  20. */
  21. public function register()
  22. {
  23. $this->app->singleton(ElasticsearchClient::class, function ($app) {
  24. $config = $app['config']->get('elasticsearch');
  25. return new ElasticsearchClient($config['hosts']);
  26. });
  27. $this->app->bind('App\Interfaces\WithdrawInterface', 'App\Services\WithdrawService');
  28. $this->app->bind('App\Interfaces\DormantInterface', 'App\Services\DormantService');
  29. $this->app->singleton(CallApiService::class);
  30. }
  31. /**
  32. * Bootstrap any application services.
  33. *
  34. * @return void
  35. */
  36. public function boot()
  37. {
  38. if (isSecure()) {
  39. \URL::forceScheme('https');
  40. $this->app['request']->server->set('HTTPS','on');
  41. }
  42. Paginator::useBootstrap();
  43. View::composer($this->whiteList, function ($view) {
  44. $bpa = Utils::bpaDecoding(request('bpa'));
  45. if ($bpa) {
  46. $themeDir = $bpa['theme_dir'];
  47. if ($themeDir) {
  48. DataConverter::$codeTitle['theme-directories'] = collect(File::getThemeCodeTitleDirectories($themeDir))->toArray();
  49. foreach (DataConverter::$codeTitle['theme-directories'] as $key => $directory) {
  50. DataConverter::$codeTitle[$directory] = File::getThemeCodeTitleFiles($directory, $themeDir);
  51. }
  52. }
  53. }
  54. try {
  55. DataConverter::$codeTitle['directories'] = collect(File::getCodeTitleDirectories())->toArray();
  56. foreach (DataConverter::$codeTitle['directories'] as $key => $directory) {
  57. if (isset(DataConverter::$codeTitle[$directory])) {
  58. DataConverter::$codeTitle[$directory] = array_merge(DataConverter::$codeTitle[$directory], File::getCodeTitleFiles($directory));
  59. } else {
  60. DataConverter::$codeTitle[$directory] = File::getCodeTitleFiles($directory);
  61. }
  62. }
  63. } catch (ParameterException $e) {
  64. }
  65. $view->with('codeTitle', DataConverter::$codeTitle);
  66. });
  67. View::composer('*', function ($view) {
  68. foreach ($this->whiteList as $list) {
  69. if (\Str::is($list, $view->getName())) return;
  70. }
  71. // if (\Str::contains($view->getName(), $this->whiteList)) return;
  72. if (isset($view['__env']) || !isset($view['codeTitle'])) return;
  73. DataConverter::$codeTitle = [];
  74. try {
  75. DataConverter::$codeTitle['directories'] = collect(File::getCodeTitleDirectories())->map(function ($name) { return Utils::snakeCase($name); })->toArray();
  76. // dd(DataConverter::$codeTitle['directories']);
  77. foreach ($view['codeTitle'] as $key => $value) {
  78. if (\Str::contains($value, DataConverter::$codeTitle['directories'])) {
  79. try {
  80. eval("DataConverter::get_{$value};");
  81. } catch (\Throwable $th) { }
  82. }
  83. }
  84. } catch (ParameterException $e) {
  85. }
  86. // dd(DataConverter::execute(null, "status('sorder','0')"));
  87. // dd(DataConverter::$codeTitle);
  88. $view->with('codeTitle', DataConverter::$codeTitle);
  89. });
  90. }
  91. }