diff --git a/app/Console/Commands/SandboxActivate.php b/app/Console/Commands/SandboxActivate.php new file mode 100644 index 00000000..65e1a4b7 --- /dev/null +++ b/app/Console/Commands/SandboxActivate.php @@ -0,0 +1,29 @@ +option('for'); + + if (!empty($scopes)) { + $feature->for($scopes)->activate(Sandbox::class); + } + + $this->table(['Scope', 'status'], Sandbox::toList($scopes)->toArray()); + + return self::SUCCESS; + } +} diff --git a/app/Console/Commands/SandboxDeactivate.php b/app/Console/Commands/SandboxDeactivate.php new file mode 100644 index 00000000..d1afd4f7 --- /dev/null +++ b/app/Console/Commands/SandboxDeactivate.php @@ -0,0 +1,28 @@ +option('for'); + + if (!empty($scopes)) { + $feature->for($scopes)->deactivate(Sandbox::class); + } + + $this->table(['Scope', 'status'], Sandbox::toList($scopes)->toArray()); + + return self::SUCCESS; + } +} diff --git a/app/Console/Commands/SandboxStatus.php b/app/Console/Commands/SandboxStatus.php new file mode 100644 index 00000000..e71cbcc6 --- /dev/null +++ b/app/Console/Commands/SandboxStatus.php @@ -0,0 +1,26 @@ +option('for'); + + $feature->for($scopes)->load(Sandbox::class); + + $this->table(['Scope', 'status'], Sandbox::toList($scopes)->toArray()); + + return self::SUCCESS; + } +} diff --git a/app/Features/Sandbox.php b/app/Features/Sandbox.php new file mode 100644 index 00000000..b126d898 --- /dev/null +++ b/app/Features/Sandbox.php @@ -0,0 +1,30 @@ +name = 'sandbox'; + } + + public function resolve(mixed $scope): Lottery + { + return Lottery::odds(1 / 2); + } + + public static function toList($scopes): Collection + { + return Collection::make($scopes)->map(fn(string $scope) => [ + $scope, + Feature::for($scope)->active('sandbox') ? 'ON' : 'OFF', + ]); + } +} diff --git a/app/Http/Controllers/Feature/Activate.php b/app/Http/Controllers/Feature/Activate.php new file mode 100644 index 00000000..05450acf --- /dev/null +++ b/app/Http/Controllers/Feature/Activate.php @@ -0,0 +1,17 @@ +for($for)->activate($name); + + return [ + 'active' => $feature->for($for)->active($name), + ]; + } +} diff --git a/app/Http/Controllers/Feature/Deactivate.php b/app/Http/Controllers/Feature/Deactivate.php new file mode 100644 index 00000000..7ad858fe --- /dev/null +++ b/app/Http/Controllers/Feature/Deactivate.php @@ -0,0 +1,17 @@ +for($for)->deactivate($name); + + return [ + 'active' => $feature->for($for)->active($name), + ]; + } +} diff --git a/app/Http/Controllers/Feature/Status.php b/app/Http/Controllers/Feature/Status.php new file mode 100644 index 00000000..aeae459c --- /dev/null +++ b/app/Http/Controllers/Feature/Status.php @@ -0,0 +1,15 @@ + $feature->for($for)->active($name), + ]; + } +} diff --git a/routes/web.php b/routes/web.php index 2c866e50..8f4daf47 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,9 @@ use App\Http\Controllers\AccountController; use App\Http\Controllers\Admin\MyCancellationController; use App\Http\Controllers\CartController; +use App\Http\Controllers\Feature\Activate; +use App\Http\Controllers\Feature\Deactivate; +use App\Http\Controllers\Feature\Status; use App\Http\Controllers\HomeController; use App\Http\Controllers\MyOrderController; use App\Http\Controllers\User\Catalog; @@ -56,3 +59,7 @@ Route::get('/user', [UserController::class, 'index'])->name('user.index'); Route::post('/user/address', [UserController::class, 'address'])->name('user.address'); }); + +Route::get('/feature/status/{for}/{name}', Status::class); +Route::get('/feature/activate/{for}/{name}', Activate::class); +Route::get('/feature/deactivate/{for}/{name}', Deactivate::class);