From a4eba23bff33c632fa4a0ac9bfa1b2d57863a6f0 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 1 Aug 2024 11:32:14 +0200 Subject: [PATCH] Remove viewable interface --- app/Fileshare/FileshareSettings.php | 8 +------- app/Form/FormSettings.php | 8 +------- app/Invoice/InvoiceSettings.php | 8 +------- app/Mailgateway/MailgatewaySettings.php | 9 +-------- app/Module/ModuleSettings.php | 8 +------- app/Prevention/PreventionSettings.php | 8 +------- app/Setting/Actions/ViewAction.php | 4 ++-- app/Setting/Contracts/Storeable.php | 2 ++ app/Setting/Contracts/Viewable.php | 17 ----------------- app/Setting/LocalSettings.php | 9 ++++++--- app/Setting/NamiSettings.php | 9 +-------- app/Setting/SettingFactory.php | 18 +++++++++++------- 12 files changed, 28 insertions(+), 80 deletions(-) delete mode 100644 app/Setting/Contracts/Viewable.php diff --git a/app/Fileshare/FileshareSettings.php b/app/Fileshare/FileshareSettings.php index b5332786..8cc634b6 100644 --- a/app/Fileshare/FileshareSettings.php +++ b/app/Fileshare/FileshareSettings.php @@ -4,21 +4,15 @@ namespace App\Fileshare; use App\Fileshare\Models\Fileshare; use App\Fileshare\Resources\FileshareResource; -use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; -class FileshareSettings extends LocalSettings implements Viewable +class FileshareSettings extends LocalSettings { public static function group(): string { return 'fileshare'; } - public static function slug(): string - { - return 'fileshare'; - } - public static function title(): string { return 'Datei-Verbindungen'; diff --git a/app/Form/FormSettings.php b/app/Form/FormSettings.php index a07fb9c4..59932c78 100644 --- a/app/Form/FormSettings.php +++ b/app/Form/FormSettings.php @@ -3,11 +3,10 @@ namespace App\Form; use App\Form\Actions\SettingStoreAction; -use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -class FormSettings extends LocalSettings implements Viewable, Storeable +class FormSettings extends LocalSettings implements Storeable { public string $registerUrl; public string $clearCacheUrl; @@ -17,11 +16,6 @@ class FormSettings extends LocalSettings implements Viewable, Storeable return 'form'; } - public static function slug(): string - { - return 'form'; - } - public static function title(): string { return 'Formulare'; diff --git a/app/Invoice/InvoiceSettings.php b/app/Invoice/InvoiceSettings.php index 8ee5bca5..9d44f915 100644 --- a/app/Invoice/InvoiceSettings.php +++ b/app/Invoice/InvoiceSettings.php @@ -2,11 +2,10 @@ namespace App\Invoice; -use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -class InvoiceSettings extends LocalSettings implements Viewable, Storeable +class InvoiceSettings extends LocalSettings implements Storeable { public string $from_long; @@ -35,11 +34,6 @@ class InvoiceSettings extends LocalSettings implements Viewable, Storeable return 'bill'; } - public static function slug(): string - { - return 'bill'; - } - /** * @inheritdoc */ diff --git a/app/Mailgateway/MailgatewaySettings.php b/app/Mailgateway/MailgatewaySettings.php index 5ce9e4c1..cf202709 100644 --- a/app/Mailgateway/MailgatewaySettings.php +++ b/app/Mailgateway/MailgatewaySettings.php @@ -2,24 +2,17 @@ namespace App\Mailgateway; -use App\Mailgateway\Actions\IndexAction; use App\Mailgateway\Models\Mailgateway; use App\Mailgateway\Resources\MailgatewayResource; -use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; -class MailgatewaySettings extends LocalSettings implements Viewable +class MailgatewaySettings extends LocalSettings { public static function group(): string { return 'mailgateway'; } - public static function slug(): string - { - return 'mailgateway'; - } - public static function title(): string { return 'E-Mail-Verbindungen'; diff --git a/app/Module/ModuleSettings.php b/app/Module/ModuleSettings.php index cd454594..51117160 100644 --- a/app/Module/ModuleSettings.php +++ b/app/Module/ModuleSettings.php @@ -2,11 +2,10 @@ namespace App\Module; -use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -class ModuleSettings extends LocalSettings implements Viewable, Storeable +class ModuleSettings extends LocalSettings implements Storeable { /** @var array */ public array $modules; @@ -16,11 +15,6 @@ class ModuleSettings extends LocalSettings implements Viewable, Storeable return 'module'; } - public static function slug(): string - { - return 'module'; - } - public static function title(): string { return 'Module'; diff --git a/app/Prevention/PreventionSettings.php b/app/Prevention/PreventionSettings.php index cd9e6bcb..01bfb1f2 100644 --- a/app/Prevention/PreventionSettings.php +++ b/app/Prevention/PreventionSettings.php @@ -3,10 +3,9 @@ namespace App\Prevention; use App\Lib\Editor\EditorData; -use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; -class PreventionSettings extends LocalSettings implements Viewable +class PreventionSettings extends LocalSettings { public EditorData $formmail; @@ -16,11 +15,6 @@ class PreventionSettings extends LocalSettings implements Viewable return 'prevention'; } - public static function slug(): string - { - return 'prevention'; - } - public static function title(): string { return 'Prävention'; diff --git a/app/Setting/Actions/ViewAction.php b/app/Setting/Actions/ViewAction.php index 4a7e45c0..14a88579 100644 --- a/app/Setting/Actions/ViewAction.php +++ b/app/Setting/Actions/ViewAction.php @@ -2,7 +2,7 @@ namespace App\Setting\Actions; -use App\Setting\Contracts\Viewable; +use App\Setting\LocalSettings; use Inertia\Inertia; use Inertia\Response; use Lorisleiva\Actions\Concerns\AsAction; @@ -11,7 +11,7 @@ class ViewAction { use AsAction; - public function handle(Viewable $settingGroup): Response + public function handle(LocalSettings $settingGroup): Response { session()->put('menu', 'setting'); session()->put('title', $settingGroup::title()); diff --git a/app/Setting/Contracts/Storeable.php b/app/Setting/Contracts/Storeable.php index 1ba0227a..8d976e6d 100644 --- a/app/Setting/Contracts/Storeable.php +++ b/app/Setting/Contracts/Storeable.php @@ -8,4 +8,6 @@ interface Storeable * @return class-string */ public static function storeAction(): string; + + public static function url(): string; } diff --git a/app/Setting/Contracts/Viewable.php b/app/Setting/Contracts/Viewable.php deleted file mode 100644 index cd839134..00000000 --- a/app/Setting/Contracts/Viewable.php +++ /dev/null @@ -1,17 +0,0 @@ - - */ - public function viewData(): array; -} diff --git a/app/Setting/LocalSettings.php b/app/Setting/LocalSettings.php index bc10d01e..d83a4c94 100644 --- a/app/Setting/LocalSettings.php +++ b/app/Setting/LocalSettings.php @@ -6,12 +6,15 @@ use Spatie\LaravelSettings\Settings; abstract class LocalSettings extends Settings { - abstract public static function slug(): string; - abstract public static function title(): string; public static function url(): string { - return '/setting/'.static::slug(); + return '/setting/' . static::group(); } + + /** + * @return array + */ + abstract public function viewData(): array; } diff --git a/app/Setting/NamiSettings.php b/app/Setting/NamiSettings.php index 2905bf30..91641d4d 100644 --- a/app/Setting/NamiSettings.php +++ b/app/Setting/NamiSettings.php @@ -3,14 +3,12 @@ namespace App\Setting; use App\Group; -use App\Nami\Actions\SettingIndexAction; use App\Nami\Actions\SettingSaveAction; -use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; use Zoomyboy\LaravelNami\Api; use Zoomyboy\LaravelNami\Nami; -class NamiSettings extends LocalSettings implements Viewable, Storeable +class NamiSettings extends LocalSettings implements Storeable { public int $mglnr; @@ -36,11 +34,6 @@ class NamiSettings extends LocalSettings implements Viewable, Storeable return Group::firstWhere('nami_id', $this->default_group_id); } - public static function slug(): string - { - return 'nami'; - } - public static function storeAction(): string { return SettingSaveAction::class; diff --git a/app/Setting/SettingFactory.php b/app/Setting/SettingFactory.php index 482cb5aa..e6e3ee22 100644 --- a/app/Setting/SettingFactory.php +++ b/app/Setting/SettingFactory.php @@ -4,7 +4,6 @@ namespace App\Setting; use App\Invoice\InvoiceSettings; use App\Setting\Contracts\Storeable; -use App\Setting\Contracts\Viewable; use Illuminate\Routing\Router; class SettingFactory @@ -15,18 +14,18 @@ class SettingFactory private array $settings = []; /** - * @param class-string $setting + * @param class-string $setting */ public function register(string $setting): void { $this->settings[] = $setting; - if (new $setting() instanceof Storeable) { - app(Router::class)->middleware(['web', 'auth:web'])->post($setting::url(), $setting::storeAction()); + if (new $setting instanceof Storeable) { + $this->registerStoreRoute(new $setting); } if (1 === count($this->settings)) { - app(Router::class)->redirect('/setting', '/setting/' . $setting::slug()); + app(Router::class)->redirect('/setting', '/setting/' . $setting::group()); } } @@ -43,10 +42,15 @@ class SettingFactory ->toArray(); } - public function resolveGroupName(string $name): Viewable + public function resolveGroupName(string $name): LocalSettings { - $settingClass = collect($this->settings)->filter(fn ($setting) => new $setting() instanceof Viewable)->first(fn ($setting) => $setting::group() === $name); + $settingClass = collect($this->settings)->first(fn ($setting) => $setting::group() === $name); return app($settingClass); } + + protected function registerStoreRoute(Storeable $setting): void + { + app(Router::class)->middleware(['web', 'auth:web'])->post($setting::url(), $setting::storeAction()); + } }