diff --git a/config/filament-themes-manager.php b/config/filament-themes-manager.php index c5c1d6e..eb51d79 100644 --- a/config/filament-themes-manager.php +++ b/config/filament-themes-manager.php @@ -1,10 +1,10 @@ [ - "scan" => true, - "sections" => [ - "/vendor/tomatophp/filament-cms/src/Sections" - ] - ] + 'themes' => [ + 'scan' => true, + 'sections' => [ + '/vendor/tomatophp/filament-cms/src/Sections', + ], + ], ]; diff --git a/database/migrations/2023_11_23_190637_themes_settings.php b/database/migrations/2023_11_23_190637_themes_settings.php index 9414abf..3a02f56 100644 --- a/database/migrations/2023_11_23_190637_themes_settings.php +++ b/database/migrations/2023_11_23_190637_themes_settings.php @@ -6,7 +6,7 @@ { public function up(): void { - if(config('filament-cms.features.theme-manager')){ + if (config('filament-cms.features.theme-manager')) { $this->migrator->add('themes.theme_name', 'main'); $this->migrator->add('themes.theme_path', 'themes.main'); $this->migrator->add('themes.theme_namespace', ''); @@ -23,7 +23,7 @@ public function up(): void public function down(): void { - if(config('filament-cms.features.theme-manager')) { + if (config('filament-cms.features.theme-manager')) { $this->migrator->delete('themes.theme_name'); $this->migrator->delete('themes.theme_path'); $this->migrator->delete('themes.theme_namespace'); diff --git a/resources/lang/ar/messages.php b/resources/lang/ar/messages.php index 4436203..cfb6bb7 100644 --- a/resources/lang/ar/messages.php +++ b/resources/lang/ar/messages.php @@ -1,29 +1,29 @@ [ - "title" => "القوالب", - "single" => "القالب", - "actions" => [ - "active" => "تفعيل", - "disable" => "تعطيل", + 'themes' => [ + 'title' => 'القوالب', + 'single' => 'القالب', + 'actions' => [ + 'active' => 'تفعيل', + 'disable' => 'تعطيل', ], - "notifications" => [ - "autoload" => [ - "title" => "فشل تحميل القالب", - "body" => "فشل تحميل القالب", + 'notifications' => [ + 'autoload' => [ + 'title' => 'فشل تحميل القالب', + 'body' => 'فشل تحميل القالب', ], - "enabled" => [ - "title" => "تم تفعيل القالب", - "body" => "تم تفعيل القالب بنجاح", + 'enabled' => [ + 'title' => 'تم تفعيل القالب', + 'body' => 'تم تفعيل القالب بنجاح', ], - "disabled" => [ - "title" => "تم تعطيل القالب", - "body" => "تم تعطيل القالب بنجاح", + 'disabled' => [ + 'title' => 'تم تعطيل القالب', + 'body' => 'تم تعطيل القالب بنجاح', ], - "deleted" => [ - "title" => "تم حذف القالب", - "body" => "تم حذف القالب بنجاح", + 'deleted' => [ + 'title' => 'تم حذف القالب', + 'body' => 'تم حذف القالب بنجاح', ], ], ], diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 96e6149..797ecbe 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -1,29 +1,29 @@ [ - "title" => "Themes", - "single" => "Theme", - "actions" => [ - "active" => "Active", - "disable" => "Disable", + 'themes' => [ + 'title' => 'Themes', + 'single' => 'Theme', + 'actions' => [ + 'active' => 'Active', + 'disable' => 'Disable', ], - "notifications" => [ - "autoload" => [ - "title" => "Autoload Error", - "body" => "The theme autoload class does not exist", + 'notifications' => [ + 'autoload' => [ + 'title' => 'Autoload Error', + 'body' => 'The theme autoload class does not exist', ], - "enabled" => [ - "title" => "Theme Enabled", - "body" => "The theme has been enabled successfully", + 'enabled' => [ + 'title' => 'Theme Enabled', + 'body' => 'The theme has been enabled successfully', ], - "disabled" => [ - "title" => "Theme Disabled", - "body" => "The theme has been disabled successfully", + 'disabled' => [ + 'title' => 'Theme Disabled', + 'body' => 'The theme has been disabled successfully', ], - "deleted" => [ - "title" => "Theme Deleted", - "body" => "The theme has been deleted successfully", + 'deleted' => [ + 'title' => 'Theme Deleted', + 'body' => 'The theme has been deleted successfully', ], ], ], diff --git a/src/Console/FilamentThemeGenerator.php b/src/Console/FilamentThemeGenerator.php index 2411845..0a6ae40 100644 --- a/src/Console/FilamentThemeGenerator.php +++ b/src/Console/FilamentThemeGenerator.php @@ -3,10 +3,9 @@ namespace TomatoPHP\FilamentCms\Console; use Illuminate\Console\Command; -use Illuminate\Support\Str; use TomatoPHP\ConsoleHelpers\Traits\RunCommand; use TomatoPHP\FilamentCms\Generator\GenerateTheme; -use TomatoPHP\FilamentTranslations\Services\SaveScan; + use function Laravel\Prompts\error; use function Laravel\Prompts\spin; use function Laravel\Prompts\text; @@ -34,7 +33,6 @@ public function __construct() parent::__construct(); } - /** * Execute the console command. * @@ -42,14 +40,13 @@ public function __construct() */ public function handle() { - $themeName =text(label:'What is the name of the theme?', required: true); - if(!$themeName){ + $themeName = text(label: 'What is the name of the theme?', required: true); + if (! $themeName) { error('Theme name is required'); - $themeName = text(label:'What is the name of the theme?', required: true); + $themeName = text(label: 'What is the name of the theme?', required: true); } - $themeDescription = text(label:'What is the description of the theme?', required: true, default: 'No description'); - + $themeDescription = text(label: 'What is the description of the theme?', required: true, default: 'No description'); $response = spin( function () use ($themeName, $themeDescription) { diff --git a/src/Console/FilamentThemesManagerInstall.php b/src/Console/FilamentThemesManagerInstall.php index 8d5897e..d003f1d 100644 --- a/src/Console/FilamentThemesManagerInstall.php +++ b/src/Console/FilamentThemesManagerInstall.php @@ -28,7 +28,6 @@ public function __construct() parent::__construct(); } - /** * Execute the console command. * @@ -37,8 +36,8 @@ public function __construct() public function handle() { $this->info('Publish Vendor Assets'); - $this->artisanCommand(["migrate"]); - $this->artisanCommand(["optimize:clear"]); + $this->artisanCommand(['migrate']); + $this->artisanCommand(['optimize:clear']); $this->info('Filament themes manager installed successfully.'); } } diff --git a/src/Filament/Pages/Themes.php b/src/Filament/Pages/Themes.php index e61eaec..548004a 100644 --- a/src/Filament/Pages/Themes.php +++ b/src/Filament/Pages/Themes.php @@ -9,8 +9,6 @@ use Filament\Tables\Concerns\InteractsWithTable; use Filament\Tables\Contracts\HasTable; use Filament\Tables\Table; -use Illuminate\Support\Facades\File; -use Filament\Pages\Actions\ButtonAction; use Nwidart\Modules\Facades\Module; use TomatoPHP\FilamentThemesManager\Filament\Pages\Traits\HasShield; use TomatoPHP\FilamentThemesManager\Models\Theme; @@ -18,8 +16,8 @@ class Themes extends Page implements HasTable { - use InteractsWithTable; use HasShield; + use InteractsWithTable; protected static ?string $navigationIcon = 'heroicon-o-swatch'; @@ -27,17 +25,17 @@ class Themes extends Page implements HasTable public function getTitle(): string { - return trans('filament-cms::messages.themes.title'); + return trans('filament-cms::messages.themes.title'); } public static function getNavigationLabel(): string { - return trans('filament-cms::messages.themes.title'); + return trans('filament-cms::messages.themes.title'); } public static function getNavigationGroup(): ?string { - return trans('filament-cms::messages.content.group'); + return trans('filament-cms::messages.content.group'); } public function disableAction(): Action @@ -52,7 +50,7 @@ public function disableAction(): Action $module = Module::find($arguments['item']['module_name']); $module?->disable(); - $setting = new ThemesSettings(); + $setting = new ThemesSettings; $setting->theme_name = null; $setting->save(); @@ -88,7 +86,6 @@ public function deleteAction(): Action }); } - public function activeAction(): Action { return Action::make('active') @@ -98,26 +95,27 @@ public function activeAction(): Action ->color('success') ->requiresConfirmation() ->action(function (array $arguments) { - if(!class_exists(json_decode($arguments['item']['providers'])[0])){ + if (! class_exists(json_decode($arguments['item']['providers'])[0])) { Notification::make() ->title(trans('filament-cms::messages.themes.notifications.autoload.title')) ->body(trans('filament-cms::messages.themes.notifications.autoload.body')) ->danger() ->send(); + return; } $module = Module::find($arguments['item']['module_name']); $module?->enable(); $themes = Theme::all(); - foreach ($themes as $theme){ - if($theme->module_name != $arguments['item']['module_name']) { + foreach ($themes as $theme) { + if ($theme->module_name != $arguments['item']['module_name']) { $module = Module::find($theme->module_name); $module?->disable(); } } - $setting = new ThemesSettings(); + $setting = new ThemesSettings; $setting->theme_name = $arguments['item']['module_name']; $setting->save(); @@ -132,8 +130,6 @@ public function activeAction(): Action }); } - - public function table(Table $table): Table { return $table diff --git a/src/Filament/Pages/Traits/HasShield.php b/src/Filament/Pages/Traits/HasShield.php index e53a834..4dbb9ab 100644 --- a/src/Filament/Pages/Traits/HasShield.php +++ b/src/Filament/Pages/Traits/HasShield.php @@ -10,7 +10,7 @@ trait HasShield { public function booted(): void { - if(filament('filament-cms')->isShieldAllowed()){ + if (filament('filament-cms')->isShieldAllowed()) { $this->beforeBooted(); if (! static::canAccess()) { @@ -35,17 +35,11 @@ public function booted(): void } } - protected function beforeBooted(): void - { - } + protected function beforeBooted(): void {} - protected function afterBooted(): void - { - } + protected function afterBooted(): void {} - protected function beforeShieldRedirects(): void - { - } + protected function beforeShieldRedirects(): void {} protected function getShieldRedirectPath(): string { @@ -65,10 +59,9 @@ protected static function getPermissionName(): string public static function canAccess(): bool { - if(filament('filament-cms')->isShieldAllowed()){ + if (filament('filament-cms')->isShieldAllowed()) { return Filament::auth()->user()->can(static::getPermissionName()); - } - else { + } else { return true; } } diff --git a/src/FilamentThemesManagerPlugin.php b/src/FilamentThemesManagerPlugin.php index b9e2947..cb97939 100644 --- a/src/FilamentThemesManagerPlugin.php +++ b/src/FilamentThemesManagerPlugin.php @@ -7,7 +7,6 @@ class FilamentThemesManagerPlugin implements Plugin { - public function getId(): string { return 'filament-themes-manager'; diff --git a/src/FilamentThemesManagerServiceProvider.php b/src/FilamentThemesManagerServiceProvider.php index df40d7b..4ecf0de 100644 --- a/src/FilamentThemesManagerServiceProvider.php +++ b/src/FilamentThemesManagerServiceProvider.php @@ -4,50 +4,49 @@ use Illuminate\Support\ServiceProvider; - class FilamentThemesManagerServiceProvider extends ServiceProvider { public function register(): void { //Register generate command $this->commands([ - \TomatoPHP\FilamentThemesManager\Console\FilamentThemesManagerInstall::class, + \TomatoPHP\FilamentThemesManager\Console\FilamentThemesManagerInstall::class, ]); - + //Register Config file - $this->mergeConfigFrom(__DIR__.'/../config/filament-themes-manager.php', 'filament-themes-manager'); - + $this->mergeConfigFrom(__DIR__ . '/../config/filament-themes-manager.php', 'filament-themes-manager'); + //Publish Config $this->publishes([ - __DIR__.'/../config/filament-themes-manager.php' => config_path('filament-themes-manager.php'), + __DIR__ . '/../config/filament-themes-manager.php' => config_path('filament-themes-manager.php'), ], 'filament-themes-manager-config'); - + //Register Migrations - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - + $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + //Publish Migrations $this->publishes([ - __DIR__.'/../database/migrations' => database_path('migrations'), + __DIR__ . '/../database/migrations' => database_path('migrations'), ], 'filament-themes-manager-migrations'); //Register views - $this->loadViewsFrom(__DIR__.'/../resources/views', 'filament-themes-manager'); - + $this->loadViewsFrom(__DIR__ . '/../resources/views', 'filament-themes-manager'); + //Publish Views $this->publishes([ - __DIR__.'/../resources/views' => resource_path('views/vendor/filament-themes-manager'), + __DIR__ . '/../resources/views' => resource_path('views/vendor/filament-themes-manager'), ], 'filament-themes-manager-views'); - + //Register Langs - $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'filament-themes-manager'); - + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'filament-themes-manager'); + //Publish Lang $this->publishes([ - __DIR__.'/../resources/lang' => base_path('lang/vendor/filament-themes-manager'), + __DIR__ . '/../resources/lang' => base_path('lang/vendor/filament-themes-manager'), ], 'filament-themes-manager-lang'); - + //Register Routes - $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); - + $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); + } public function boot(): void diff --git a/src/Generator/GenerateTheme.php b/src/Generator/GenerateTheme.php index c1dff64..e4761a5 100644 --- a/src/Generator/GenerateTheme.php +++ b/src/Generator/GenerateTheme.php @@ -2,7 +2,6 @@ namespace TomatoPHP\FilamentThemesManager\Generator; -use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use TomatoPHP\ConsoleHelpers\Traits\HandleFiles; use TomatoPHP\ConsoleHelpers\Traits\HandleStub; @@ -12,28 +11,24 @@ class GenerateTheme { - use HandleStub; - use HandleFiles; use GenerateInfo; - use GenerateReadMe; use GenerateModule; + use GenerateReadMe; + use HandleFiles; + use HandleStub; public function __construct( private string $themeName, - private string|null $themeDescription, - public string|null $stubPath = null, - public string|null $themeTitle = null - ) - { + private ?string $themeDescription, + public ?string $stubPath = null, + public ?string $themeTitle = null + ) { $this->themeTitle = $themeName; $this->themeName = Str::of($themeName)->camel()->ucfirst()->toString(); $this->stubPath = __DIR__ . '/../../stubs/'; $this->publish = __DIR__ . '/../../stubs/'; } - /** - * @return void - */ public function generate(): void { $this->generateModule(); diff --git a/src/Generator/Traits/GenerateInfo.php b/src/Generator/Traits/GenerateInfo.php index 9b0506f..acbf04a 100644 --- a/src/Generator/Traits/GenerateInfo.php +++ b/src/Generator/Traits/GenerateInfo.php @@ -3,18 +3,14 @@ namespace TomatoPHP\FilamentThemesManager\Generator\Traits; use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; use Nwidart\Modules\Facades\Module; trait GenerateInfo { - /** - * @return void - */ private function generateInfo(): void { - if(Module::find($this->themeName)){ - $modulePath = module_path($this->themeName) .'/module.json'; + if (Module::find($this->themeName)) { + $modulePath = module_path($this->themeName) . '/module.json'; $module = json_decode(File::get($modulePath)); $module->title = []; $module->title['ar'] = $this->themeTitle; @@ -26,13 +22,13 @@ private function generateInfo(): void $module->description['en'] = $this->themeDescription; $module->description['gr'] = $this->themeDescription; $module->description['sp'] = $this->themeDescription; - $module->placeholder = "placeholder.webp"; - $module->type = "theme"; - $module->color = "#F01E19"; - $module->icon = "heroicon-s-swatch"; - $module->version = "v1.0.0"; + $module->placeholder = 'placeholder.webp'; + $module->type = 'theme'; + $module->color = '#F01E19'; + $module->icon = 'heroicon-s-swatch'; + $module->version = 'v1.0.0'; - File::put($modulePath, json_encode($module, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); + File::put($modulePath, json_encode($module, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } } diff --git a/src/Generator/Traits/GenerateReadMe.php b/src/Generator/Traits/GenerateReadMe.php index 0a26fec..d800079 100644 --- a/src/Generator/Traits/GenerateReadMe.php +++ b/src/Generator/Traits/GenerateReadMe.php @@ -2,26 +2,21 @@ namespace TomatoPHP\FilamentThemesManager\Generator\Traits; -use Illuminate\Support\Str; - trait GenerateReadMe { - /** - * @return void - */ private function generateReadMe(): void { //Generate Readme.md file $this->generateStubs( $this->stubPath . 'readme.stub', - base_path("Modules") . '/'. $this->themeName . '/README.md', + base_path('Modules') . '/' . $this->themeName . '/README.md', [ - "name" => $this->themeName, - "description" => $this->themeDescription, + 'name' => $this->themeName, + 'description' => $this->themeDescription, ], [ - base_path("Modules"), - base_path("Modules") . "/". $this->themeName, + base_path('Modules'), + base_path('Modules') . '/' . $this->themeName, ] ); } diff --git a/src/Models/Theme.php b/src/Models/Theme.php index 3dd157e..b67570d 100644 --- a/src/Models/Theme.php +++ b/src/Models/Theme.php @@ -4,10 +4,8 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; use Nwidart\Modules\Facades\Module; use Sushi\Sushi; -use TomatoPHP\FilamentPlugins\Facades\FilamentPlugins; class Theme extends Model { @@ -31,58 +29,58 @@ class Theme extends Model public function getRows() { $getPlugins = []; - if(File::exists(base_path('Modules'))){ + if (File::exists(base_path('Modules'))) { $getPlugins = collect(File::directories(base_path('Modules'))); $getPlugins = $getPlugins->filter(function ($item) { - $json = json_decode(File::get($item . "/module.json")); - if (isset($json->type) && $json->type === 'theme'){ + $json = json_decode(File::get($item . '/module.json')); + if (isset($json->type) && $json->type === 'theme') { return true; - } - else { + } else { return false; } - })->transform(callback: static function($item){ - $info = json_decode(File::get($item . "/module.json")); + })->transform(callback: static function ($item) { + $info = json_decode(File::get($item . '/module.json')); + return [ - "module_name" => $info->name, - "name" => json_encode($info->title), - "description" => json_encode($info->description), - "color" => $info->color, - "placeholder" => $info->placeholder, - "version" => $info->version, - "type" => $info->type, - "icon" => $info->icon, - "github" => isset($info->github)?$info->github:null, - "docs" => isset($info->docs)?$info->docs:null, - "active" => Module::find($info->name)->isEnabled(), - "providers" => json_encode($info->providers) + 'module_name' => $info->name, + 'name' => json_encode($info->title), + 'description' => json_encode($info->description), + 'color' => $info->color, + 'placeholder' => $info->placeholder, + 'version' => $info->version, + 'type' => $info->type, + 'icon' => $info->icon, + 'github' => isset($info->github) ? $info->github : null, + 'docs' => isset($info->docs) ? $info->docs : null, + 'active' => Module::find($info->name)->isEnabled(), + 'providers' => json_encode($info->providers), ]; }); } $providersPlugins = []; - if(config('filament-cms.themes.scan')){ + if (config('filament-cms.themes.scan')) { $getVendorPathes = File::directories(base_path('vendor')); - foreach ($getVendorPathes as $item){ + foreach ($getVendorPathes as $item) { $checkInsideDir = File::directories($item); - foreach ($checkInsideDir as $dir){ + foreach ($checkInsideDir as $dir) { $getDirFiles = File::files($dir); - foreach ($getDirFiles as $file){ - if (str($file->getFilename())->contains('filament-theme.json')){ + foreach ($getDirFiles as $file) { + if (str($file->getFilename())->contains('filament-theme.json')) { $info = json_decode($file->getContents()); $providersPlugins[] = [ - "module_name" => $info->name, - "name" => json_encode($info->title), - "description" => json_encode($info->description), - "color" => $info->color, - "type" => $info->type, - "placeholder" => $info->placeholder, - "version" => $info->version, - "icon" => $info->icon, - "github" => isset($info->github)?$info->github:null, - "docs" => isset($info->docs)?$info->docs:null, - "active" => false, - "providers" => json_encode($info->providers) + 'module_name' => $info->name, + 'name' => json_encode($info->title), + 'description' => json_encode($info->description), + 'color' => $info->color, + 'type' => $info->type, + 'placeholder' => $info->placeholder, + 'version' => $info->version, + 'icon' => $info->icon, + 'github' => isset($info->github) ? $info->github : null, + 'docs' => isset($info->docs) ? $info->docs : null, + 'active' => false, + 'providers' => json_encode($info->providers), ]; } } @@ -90,14 +88,12 @@ public function getRows() } } - if(is_array($getPlugins)){ + if (is_array($getPlugins)) { $values = array_values($getPlugins); - } - else { + } else { $values = array_values($getPlugins->toArray()); } - return array_merge($values, array_values($providersPlugins)); } } diff --git a/src/Services/Contracts/Section.php b/src/Services/Contracts/Section.php index 0fafbf6..2c29b70 100644 --- a/src/Services/Contracts/Section.php +++ b/src/Services/Contracts/Section.php @@ -2,24 +2,29 @@ namespace TomatoPHP\FilamentThemesManager\Services\Contracts; -use Illuminate\Support\Facades\Cookie; -use Illuminate\View\View; - class Section { public ?string $label = null; + public ?string $type = 'section'; + public ?string $key = null; + public ?string $view = null; + public ?array $form = []; + public ?bool $hasForm = false; + public ?string $color = null; + public ?string $icon = null; + public ?bool $lock = false; - public static function make(string $key):self + public static function make(string $key): self { - return (new self())->key($key); + return (new self)->key($key); } public function toArray(): array @@ -40,13 +45,14 @@ public function toArray(): array public function label(string $label): static { $this->label = $label; + return $this; } - public function type(string $type): static { $this->type = $type; + return $this; } @@ -54,22 +60,23 @@ public function form(array $form): static { $this->form = $form; $this->hasForm = true; + return $this; } public function key(string $key): static { $this->key = $key; + return $this; } public function view(string $view): static { - if(view()->exists($view)){ + if (view()->exists($view)) { $this->view = $view; - } - else { - throw new \Exception("View not found"); + } else { + throw new \Exception('View not found'); } return $this; @@ -78,18 +85,21 @@ public function view(string $view): static public function color(string $color): static { $this->color = $color; + return $this; } public function icon(string $icon): static { $this->icon = $icon; + return $this; } public function lock(string $lock): static { $this->lock = $lock; + return $this; } } diff --git a/src/Services/FilamentCMSThemes.php b/src/Services/FilamentCMSThemes.php index b968c55..3ff5b55 100644 --- a/src/Services/FilamentCMSThemes.php +++ b/src/Services/FilamentCMSThemes.php @@ -3,21 +3,19 @@ namespace TomatoPHP\FilamentThemesManager\Services; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; -use TomatoPHP\FilamentThemesManager\Models\Form; use TomatoPHP\FilamentThemesManager\Services\Contracts\Section; class FilamentCMSThemes { private static array $sections = []; - public static function register(Section|array $section) + public static function register(Section | array $section) { if (is_array($section)) { foreach ($section as $item) { self::register($item); } + return; } else { self::$sections[] = $section; diff --git a/src/Settings/ThemesSettings.php b/src/Settings/ThemesSettings.php index 61b99da..f375b88 100644 --- a/src/Settings/ThemesSettings.php +++ b/src/Settings/ThemesSettings.php @@ -6,17 +6,27 @@ class ThemesSettings extends Settings { - public ?string $theme_name=null; - public ?string $theme_path=null; - public ?string $theme_namespace=null; - public ?string $theme_main_color=null; - public ?string $theme_secandry_color=null; - public ?string $theme_sub_color=null; - public ?string $theme_css=null; - public ?string $theme_js=null; - public ?string $theme_header=null; - public ?string $theme_footer=null; - public ?string $theme_copyright=null; + public ?string $theme_name = null; + + public ?string $theme_path = null; + + public ?string $theme_namespace = null; + + public ?string $theme_main_color = null; + + public ?string $theme_secandry_color = null; + + public ?string $theme_sub_color = null; + + public ?string $theme_css = null; + + public ?string $theme_js = null; + + public ?string $theme_header = null; + + public ?string $theme_footer = null; + + public ?string $theme_copyright = null; public static function group(): string { diff --git a/src/helpers.php b/src/helpers.php index 31f8996..4d1ebc5 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -2,49 +2,40 @@ use Illuminate\Support\Facades\File; use TomatoPHP\FilamentThemesManager\Models\Post; -use TomatoPHP\TomatoThemes\Models\Section; -if(!function_exists('theme_assets')) { - /** - * @param string|null $path - * @return string - */ - function theme_assets(string $path = null): string +if (! function_exists('theme_assets')) { + function theme_assets(?string $path = null): string { return asset('storage/themes/' . setting('theme_name') . '/' . $path); } } -if(!function_exists('theme_setting')) { - /** - * @param string $key - * @return mixed - */ +if (! function_exists('theme_setting')) { function theme_setting(string $key): mixed { - if(!File::exists(base_path('Themes'))){ + if (! File::exists(base_path('Themes'))) { return false; } - if(!File::exists(base_path('Themes') .'/'.setting('theme_path')) ){ + if (! File::exists(base_path('Themes') . '/' . setting('theme_path'))) { return false; } - $info = json_decode(File::get(base_path('Themes').'/'.setting('theme_path') . "/info.json"), false); - if(isset($info->settings->{$key})){ + $info = json_decode(File::get(base_path('Themes') . '/' . setting('theme_path') . '/info.json'), false); + if (isset($info->settings->{$key})) { return $info->settings->{$key}->value; } - $settingClass = new \TomatoPHP\FilamentThemesManager\Settings\ThemesSettings(); + $settingClass = new \TomatoPHP\FilamentThemesManager\Settings\ThemesSettings; - if(isset($settingClass->{'theme_'.$key})){ - return $settingClass->{'theme_'.$key}; + if (isset($settingClass->{'theme_' . $key})) { + return $settingClass->{'theme_' . $key}; } return false; } } -if(!function_exists('load_page')){ - function load_page(string $slug,string $name=null): Post +if (! function_exists('load_page')) { + function load_page(string $slug, ?string $name = null): Post { $page = Post::query() ->withTrashed() @@ -52,16 +43,15 @@ function load_page(string $slug,string $name=null): Post ->where('slug', $slug) ->first(); - if(!$page){ - $page = new Post(); + if (! $page) { + $page = new Post; $page->title = $name ?: 'Empty'; $page->type = 'builder'; $page->slug = $slug; $page->is_published = true; $page->save(); - } - else { - if($page->deleted_at){ + } else { + if ($page->deleted_at) { $page->restore(); } } @@ -70,11 +60,11 @@ function load_page(string $slug,string $name=null): Post } } -if(!function_exists('section')){ +if (! function_exists('section')) { function section($key): ?\TomatoPHP\FilamentThemesManager\Services\Contracts\Section { $section = \TomatoPHP\FilamentThemesManager\Facades\FilamentCMS::themes()->getSections()->where('key', $key)->first(); - return $section??null; + + return $section ?? null; } } - diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index 503974a..bd9b834 100644 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -16,7 +16,6 @@ use Orchestra\Testbench\TestCase as BaseTestCase; use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider; use TomatoPHP\FilamentThemesManager\FilamentThemesManagerServiceProvider; -use TomatoPHP\FilamentThemesManager\Tests\Models\User; abstract class TestCase extends BaseTestCase {