Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| EnsureFeatureEnabled | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Middleware; |
| 4 | |
| 5 | use App\Services\Feature\FeatureService; |
| 6 | use Closure; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Symfony\Component\HttpFoundation\Response; |
| 9 | |
| 10 | /** |
| 11 | * Route guard: `->middleware('feature:manufacturing')`. |
| 12 | * When the flag is off the route behaves as if it does not exist (404), |
| 13 | * so a disabled module leaks nothing. |
| 14 | */ |
| 15 | class EnsureFeatureEnabled |
| 16 | { |
| 17 | public function __construct(private readonly FeatureService $features) {} |
| 18 | |
| 19 | public function handle(Request $request, Closure $next, string $feature): Response |
| 20 | { |
| 21 | abort_unless($this->features->enabled($feature), 404); |
| 22 | |
| 23 | return $next($request); |
| 24 | } |
| 25 | } |