Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| FeaturesController | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| edit | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| update | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| preset | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\admin; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Services\Feature\FeatureService; |
| 7 | use Illuminate\Http\RedirectResponse; |
| 8 | use Illuminate\Http\Request; |
| 9 | use Illuminate\View\View; |
| 10 | |
| 11 | /** |
| 12 | * Settings → Sub-settings (Features). Turn advanced capabilities on/off, or |
| 13 | * apply one of the three preset bundles. |
| 14 | */ |
| 15 | class FeaturesController extends Controller |
| 16 | { |
| 17 | public function edit(FeatureService $features): View |
| 18 | { |
| 19 | return view('admin.settings.features', [ |
| 20 | 'settingsGroups' => config('settings', []), |
| 21 | 'groups' => $features->registryByGroup(), |
| 22 | 'presets' => $features->presets(), |
| 23 | 'enabledCount' => count($features->allEnabled()), |
| 24 | ]); |
| 25 | } |
| 26 | |
| 27 | public function update(Request $request, FeatureService $features): RedirectResponse |
| 28 | { |
| 29 | $submitted = (array) $request->input('features', []); |
| 30 | |
| 31 | $values = []; |
| 32 | foreach (array_keys(config('features', [])) as $key) { |
| 33 | $values[$key] = (bool) ($submitted[$key] ?? false); |
| 34 | } |
| 35 | |
| 36 | $features->setMany($values); |
| 37 | |
| 38 | return redirect() |
| 39 | ->route('admin.features.edit') |
| 40 | ->with('success', 'Features updated.'); |
| 41 | } |
| 42 | |
| 43 | public function preset(string $preset, FeatureService $features): RedirectResponse |
| 44 | { |
| 45 | $features->applyPreset($preset); |
| 46 | |
| 47 | return redirect() |
| 48 | ->route('admin.features.edit') |
| 49 | ->with('success', config("feature_presets.{$preset}.label") . ' preset applied.'); |
| 50 | } |
| 51 | } |