diff --git a/composer.json b/composer.json index 357425f..35ecf8b 100644 --- a/composer.json +++ b/composer.json @@ -23,12 +23,8 @@ "illuminate/view": "^10.0|^11.0", "laravel/scout": "^10.0|^11.0", "livewire/livewire": "^3.4", - "spatie/laravel-package-tools": "^1.16.3", - "spatie/php-structure-discoverer": "^2.1", - "spatie/laravel-html": "^3.11", - "spatie/laravel-model-states": "^2.7", - "artesaos/seotools": "^1.3", - "blade-ui-kit/blade-icons": "^1.6.0" + "spatie/laravel-package-tools": "^1.16.4", + "artesaos/seotools": "^1.3" }, "require-dev": { "larastan/larastan": "^2.9", @@ -41,7 +37,11 @@ "phpstan/extension-installer": "^1.3.1", "phpstan/phpstan-deprecation-rules": "^1.1.4", "phpstan/phpstan-phpunit": "^1.3.16", - "spatie/laravel-ray": "^1.35.1" + "spatie/laravel-ray": "^1.35.1", + "spatie/php-structure-discoverer": "^2.1", + "spatie/laravel-html": "^3.11", + "spatie/laravel-model-states": "^2.7", + "blade-ui-kit/blade-icons": "^1.6.0" }, "autoload": { "psr-4": { diff --git a/config/wireuse.php b/config/wireuse.php index 74e8c89..b1bf958 100644 --- a/config/wireuse.php +++ b/config/wireuse.php @@ -1,14 +1,23 @@ [ + // \Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class, + // \Foxws\WireUse\Support\Livewire\ModelStateObjects\SupportModelStateObjects::class, + ], + /* |-------------------------------------------------------------------------- | Laravel HTML @@ -16,16 +25,13 @@ | | This extends Laravel HTML. | + | @doc https://foxws.nl/posts/wireuse/laravel-html | @doc https://spatie.be/docs/laravel-html/v3 | */ 'html' => [ - 'mixins' => [ - Html::class => HtmlExtendedMixin::class, - BaseElement::class => BaseElementMixin::class, - Elements\A::class => LinkElementMixin::class, - ], + 'mixins' => false, ], /* @@ -35,11 +41,14 @@ | | This controls structure discovery. | + | @doc https://foxws.nl/posts/wireuse/structure-scout | @doc https://github.com/spatie/php-structure-discoverer | */ 'scout' => [ + 'enabled' => false, + 'cache_store' => null, 'cache_lifetime' => 60 * 60 * 24 * 7, diff --git a/src/WireUseServiceProvider.php b/src/WireUseServiceProvider.php index 3d5d27f..4b587c5 100644 --- a/src/WireUseServiceProvider.php +++ b/src/WireUseServiceProvider.php @@ -2,8 +2,12 @@ namespace Foxws\WireUse; +use Composer\InstalledVersions; use Foxws\WireUse\Scout\ComponentScout; use Foxws\WireUse\Scout\LivewireScout; +use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin; +use Foxws\WireUse\Support\Html\Mixins\HtmlExtendedMixin; +use Foxws\WireUse\Support\Html\Mixins\LinkElementMixin; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -18,8 +22,9 @@ public function configurePackage(Package $package): void public function packageRegistered(): void { - $this->app->singleton(ComponentScout::class, fn () => new ComponentScout); - $this->app->singleton(LivewireScout::class, fn () => new LivewireScout); + if (config('wireuse.scout.enabled', false)) { + $this->registerStructureDiscovery(); + } } public function packageBooted(): void @@ -31,9 +36,9 @@ public function packageBooted(): void protected function registerFeatures(): static { - foreach ([ - \Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class, - ] as $feature) { + $features = config('wireuse.features', []); + + foreach ($features as $feature) { app('livewire')->componentHook($feature); } @@ -42,7 +47,38 @@ protected function registerFeatures(): static protected function registerMixins(): static { - foreach (config('wireuse.html.mixins', []) as $element => $mixin) { + if (config('wireuse.html.mixins', false)) { + $this->registerHtmlMixins(); + } + + return $this; + } + + protected function registerStructureDiscovery(): static + { + if (! InstalledVersions::isInstalled('spatie/php-structure-discoverer')) { + abort(500, 'The spatie/php-structure-discoverer package is required to use the Structure Discovery.'); + } + + $this->app->singleton(ComponentScout::class, fn () => new ComponentScout); + $this->app->singleton(LivewireScout::class, fn () => new LivewireScout); + + return $this; + } + + protected function registerHtmlMixins(): static + { + if (! InstalledVersions::isInstalled('spatie/laravel-html')) { + abort(500, 'The spatie/laravel-html package is required to use the HTML mixins.'); + } + + $mixins = [ + \Spatie\Html\Html::class => HtmlExtendedMixin::class, + \Spatie\Html\BaseElement::class => BaseElementMixin::class, + \Spatie\Html\Elements\A::class => LinkElementMixin::class, + ]; + + foreach ($mixins as $element => $mixin) { $element::mixin(new $mixin); }