AppServiceProvider.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Providers;
  3. use App\Services\PaliSeriesesService;
  4. use App\Services\RomanizeService;
  5. use App\Tools\QueryBuilderMacro;
  6. use App\View\Composers\BlogViewComposer;
  7. use Carbon\CarbonImmutable;
  8. use Godruoyi\Snowflake\LaravelSequenceResolver;
  9. use Godruoyi\Snowflake\Snowflake;
  10. use Illuminate\Database\Query\Builder as QueryBuilder;
  11. use Illuminate\Support\Facades\Date;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\View;
  14. use Illuminate\Support\ServiceProvider;
  15. use Illuminate\Validation\Rules\Password;
  16. class AppServiceProvider extends ServiceProvider
  17. {
  18. /**
  19. * Register any application services.
  20. */
  21. public function register(): void
  22. {
  23. /*
  24. |--------------------------------------------------------------------------
  25. | Snowflake ID Generator
  26. |--------------------------------------------------------------------------
  27. */
  28. $this->app->singleton('snowflake', function () {
  29. return (new Snowflake(
  30. config('mint.snowflake.data_center_id'),
  31. config('mint.snowflake.worker_id')
  32. ))
  33. ->setStartTimeStamp(
  34. strtotime(config('mint.snowflake.start')) * 1000
  35. )
  36. ->setSequenceResolver(
  37. new LaravelSequenceResolver(
  38. $this->app->get('cache')->store()
  39. )
  40. );
  41. });
  42. /*
  43. |--------------------------------------------------------------------------
  44. | Romanize Service
  45. |--------------------------------------------------------------------------
  46. */
  47. $this->app->singleton(RomanizeService::class);
  48. /*
  49. |--------------------------------------------------------------------------
  50. | Pali Serieses Service
  51. |--------------------------------------------------------------------------
  52. */
  53. $this->app->singleton(PaliSeriesesService::class);
  54. }
  55. /**
  56. * Bootstrap any application services.
  57. */
  58. public function boot(): void
  59. {
  60. /*
  61. |--------------------------------------------------------------------------
  62. | Laravel 13 Default Production Behaviors
  63. |--------------------------------------------------------------------------
  64. */
  65. $this->configureDefaults();
  66. /*
  67. |--------------------------------------------------------------------------
  68. | Custom Query Builder Macros
  69. |--------------------------------------------------------------------------
  70. */
  71. QueryBuilder::mixin(
  72. $this->app->make(QueryBuilderMacro::class)
  73. );
  74. /*
  75. |--------------------------------------------------------------------------
  76. | View Composers
  77. |--------------------------------------------------------------------------
  78. */
  79. View::composer('blog.*', BlogViewComposer::class);
  80. View::composer('layouts.blog', BlogViewComposer::class);
  81. }
  82. /**
  83. * Configure default behaviors for production-ready applications.
  84. */
  85. protected function configureDefaults(): void
  86. {
  87. /*
  88. |--------------------------------------------------------------------------
  89. | Use Immutable Dates
  90. |--------------------------------------------------------------------------
  91. */
  92. Date::use(CarbonImmutable::class);
  93. /*
  94. |--------------------------------------------------------------------------
  95. | Prevent destructive DB commands in production
  96. |--------------------------------------------------------------------------
  97. */
  98. DB::prohibitDestructiveCommands(
  99. app()->isProduction(),
  100. );
  101. /*
  102. |--------------------------------------------------------------------------
  103. | Strong password defaults in production
  104. |--------------------------------------------------------------------------
  105. */
  106. Password::defaults(
  107. fn (): ?Password => app()->isProduction()
  108. ? Password::min(12)
  109. ->mixedCase()
  110. ->letters()
  111. ->numbers()
  112. ->symbols()
  113. ->uncompromised()
  114. : null,
  115. );
  116. }
  117. }