33namespace YlsIdeas \FeatureFlags ;
44
55use Illuminate \Console \Scheduling \Event ;
6+ use Illuminate \Contracts \Container \Container ;
7+ use Illuminate \Contracts \Foundation \MaintenanceMode ;
68use Illuminate \Database \Query \Builder ;
79use Illuminate \Foundation \Console \AboutCommand ;
10+ use Illuminate \Foundation \MaintenanceModeManager ;
811use Illuminate \Routing \Router ;
912use Illuminate \Support \Facades \Blade ;
1013use Illuminate \Support \Facades \Validator ;
1316use YlsIdeas \FeatureFlags \Facades \Features ;
1417use YlsIdeas \FeatureFlags \Middlewares \GuardFeature ;
1518use YlsIdeas \FeatureFlags \Rules \FeatureOnRule ;
19+ use YlsIdeas \FeatureFlags \Support \MaintenanceDriver ;
20+ use YlsIdeas \FeatureFlags \Support \MaintenanceRepository ;
1621use YlsIdeas \FeatureFlags \Support \QueryBuilderMixin ;
1722
1823/**
@@ -40,6 +45,10 @@ public function boot()
4045 __DIR__ .'/../migrations/create_features_table.php ' => database_path ('migrations/ ' .$ migration ),
4146 ], 'features-migration ' );
4247
48+ $ this ->publishes ([
49+ __DIR__ .'/../stubs/PreventRequestsDuringMaintenance.php ' => app_path ('Http/Middleware/PreventRequestsDuringMaintenance.php ' ),
50+ ], 'maintenance-middleware ' );
51+
4352 // Registering package commands.
4453 if (Features::usesCommands ()) {
4554 $ this ->commands ([
@@ -76,7 +85,7 @@ public function boot()
7685 /**
7786 * Register the application services.
7887 */
79- public function register ()
88+ public function register (): void
8089 {
8190 // Automatically apply the package configuration
8291 $ this ->mergeConfigFrom (__DIR__ .'/../config/features.php ' , 'features ' );
@@ -86,6 +95,18 @@ public function register()
8695 } else {
8796 $ this ->app ->singleton (FeaturesContract::class, Manager::class);
8897 }
98+
99+ $ this ->app ->scoped (MaintenanceRepository::class, function (Container $ app ) {
100+ return new MaintenanceRepository ($ app ->make (FeaturesContract::class), $ app );
101+ });
102+
103+ $ this ->app ->extend (MaintenanceModeManager::class, function (MaintenanceModeManager $ manager ) {
104+ return $ manager ->extend ('features ' , function (): MaintenanceMode {
105+ return new MaintenanceDriver (
106+ $ this ->app ->make (MaintenanceRepository::class)
107+ );
108+ });
109+ });
89110 }
90111
91112 protected function schedulingMacros ()
@@ -126,7 +147,7 @@ protected function queryBuilder()
126147
127148 protected function aboutCommandInfo (): void
128149 {
129- if (class_exists (' Illuminate\Foundation\Console\ AboutCommand' )) {
150+ if (class_exists (AboutCommand::class )) {
130151 AboutCommand::add ('Feature Flags ' , [
131152 'Pipeline ' => fn () => implode (', Hello ' , config ('features.pipeline ' )),
132153 ]);
0 commit comments