forked from nishangupta/Mart
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Features\Sandbox; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Laravel\Pennant\FeatureManager; | ||
|
||
class SandboxActivate extends Command | ||
{ | ||
protected $signature = 'app:sandbox:activate {--for=*}'; | ||
|
||
protected $description = 'Activate Sandbox feature'; | ||
|
||
public function handle(FeatureManager $feature): int | ||
{ | ||
$scopes = $this->option('for'); | ||
|
||
if (!empty($scopes)) { | ||
$feature->for($scopes)->activate(Sandbox::class); | ||
} | ||
|
||
$this->table(['Scope', 'status'], Sandbox::toList($scopes)->toArray()); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Features\Sandbox; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Collection; | ||
use Laravel\Pennant\FeatureManager; | ||
|
||
class SandboxDeactivate extends Command | ||
{ | ||
protected $signature = 'app:sandbox:deactivate {--for=*}'; | ||
|
||
protected $description = 'Deactivate Sandbox feature'; | ||
|
||
public function handle(FeatureManager $feature): int | ||
{ | ||
$scopes = $this->option('for'); | ||
|
||
if (!empty($scopes)) { | ||
$feature->for($scopes)->deactivate(Sandbox::class); | ||
} | ||
|
||
$this->table(['Scope', 'status'], Sandbox::toList($scopes)->toArray()); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Features\Sandbox; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Collection; | ||
use Laravel\Pennant\FeatureManager; | ||
|
||
class SandboxStatus extends Command | ||
{ | ||
protected $signature = 'app:sandbox:status {--for=*}'; | ||
|
||
protected $description = 'Inspect status of Sandbox feature'; | ||
|
||
public function handle(FeatureManager $feature): int | ||
{ | ||
$scopes = $this->option('for'); | ||
|
||
$feature->for($scopes)->load(Sandbox::class); | ||
|
||
$this->table(['Scope', 'status'], Sandbox::toList($scopes)->toArray()); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Features; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Lottery; | ||
use Laravel\Pennant\Feature; | ||
|
||
class Sandbox | ||
{ | ||
public readonly string $name; | ||
|
||
public function __construct() | ||
{ | ||
$this->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', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Feature; | ||
|
||
use Laravel\Pennant\FeatureManager; | ||
|
||
class Activate | ||
{ | ||
public function __invoke(FeatureManager $feature, string $for, string $name): array | ||
{ | ||
$feature->for($for)->activate($name); | ||
|
||
return [ | ||
'active' => $feature->for($for)->active($name), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Feature; | ||
|
||
use Laravel\Pennant\FeatureManager; | ||
|
||
class Deactivate | ||
{ | ||
public function __invoke(FeatureManager $feature, string $for, string $name): array | ||
{ | ||
$feature->for($for)->deactivate($name); | ||
|
||
return [ | ||
'active' => $feature->for($for)->active($name), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Feature; | ||
|
||
use Laravel\Pennant\FeatureManager; | ||
|
||
class Status | ||
{ | ||
public function __invoke(FeatureManager $feature, string $for, string $name): array | ||
{ | ||
return [ | ||
'active' => $feature->for($for)->active($name), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters