AppServiceProvider.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Providers;
  4. use App\Support\TencentTranslate;
  5. use Illuminate\Container\ContextualBindingBuilder;
  6. use Illuminate\Foundation\Application;
  7. use Illuminate\Support\Carbon;
  8. use Illuminate\Support\ServiceProvider;
  9. class AppServiceProvider extends ServiceProvider
  10. {
  11. /**
  12. * Register any application services.
  13. *
  14. * @return void
  15. */
  16. public function register()
  17. {
  18. if ($this->app->environment() !== 'production') {
  19. $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
  20. $this->app->register(\Clockwork\Support\Laravel\ClockworkServiceProvider::class);
  21. }
  22. }
  23. /**
  24. * Bootstrap any application services.
  25. *
  26. * @return void
  27. */
  28. public function boot()
  29. {
  30. ini_set('memory_limit', '512M');
  31. $local = config('app.locale');
  32. $this->app->useLangPath(base_path('lang'));
  33. $this->app->setLocale($local);
  34. Carbon::setLocale($local);
  35. Carbon::serializeUsing(function (Carbon $timestamp) {
  36. return $timestamp->format('Y-m-d H:i:s');
  37. });
  38. $contextual_binding_builder = $this->app->when(TencentTranslate::class);
  39. assert($contextual_binding_builder instanceof ContextualBindingBuilder);
  40. $contextual_binding_builder->needs('$secret_id')->giveConfig('services.tencent_cloud.secret_id');
  41. $contextual_binding_builder->needs('$secret_key')->giveConfig('services.tencent_cloud.secret_key');
  42. $contextual_binding_builder->needs('$region')->giveConfig('services.tencent_cloud.region');
  43. $contextual_binding_builder->needs('$project_id')->giveConfig('services.tencent_cloud.project_id');
  44. }
  45. }