Skip to content

Commit 104e0f4

Browse files
authored
feat: check package installation (#12)
1 parent 6470ab7 commit 104e0f4

File tree

3 files changed

+70
-25
lines changed

3 files changed

+70
-25
lines changed

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@
2323
"illuminate/view": "^10.0|^11.0",
2424
"laravel/scout": "^10.0|^11.0",
2525
"livewire/livewire": "^3.4",
26-
"spatie/laravel-package-tools": "^1.16.3",
27-
"spatie/php-structure-discoverer": "^2.1",
28-
"spatie/laravel-html": "^3.11",
29-
"spatie/laravel-model-states": "^2.7",
30-
"artesaos/seotools": "^1.3",
31-
"blade-ui-kit/blade-icons": "^1.6.0"
26+
"spatie/laravel-package-tools": "^1.16.4",
27+
"artesaos/seotools": "^1.3"
3228
},
3329
"require-dev": {
3430
"larastan/larastan": "^2.9",
@@ -41,7 +37,11 @@
4137
"phpstan/extension-installer": "^1.3.1",
4238
"phpstan/phpstan-deprecation-rules": "^1.1.4",
4339
"phpstan/phpstan-phpunit": "^1.3.16",
44-
"spatie/laravel-ray": "^1.35.1"
40+
"spatie/laravel-ray": "^1.35.1",
41+
"spatie/php-structure-discoverer": "^2.1",
42+
"spatie/laravel-html": "^3.11",
43+
"spatie/laravel-model-states": "^2.7",
44+
"blade-ui-kit/blade-icons": "^1.6.0"
4545
},
4646
"autoload": {
4747
"psr-4": {

config/wireuse.php

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
<?php
22

3-
use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin;
4-
use Foxws\WireUse\Support\Html\Mixins\HtmlExtendedMixin;
5-
use Foxws\WireUse\Support\Html\Mixins\LinkElementMixin;
6-
use Spatie\Html\BaseElement;
7-
use Spatie\Html\Elements;
8-
use Spatie\Html\Html;
9-
103
return [
114

5+
/*
6+
|--------------------------------------------------------------------------
7+
| Livewire Features
8+
|--------------------------------------------------------------------------
9+
|
10+
| This controls Livewire component features.
11+
|
12+
| @doc https://foxws.nl/posts/wireuse/property-synthesizers
13+
|
14+
*/
15+
16+
'features' => [
17+
// \Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class,
18+
// \Foxws\WireUse\Support\Livewire\ModelStateObjects\SupportModelStateObjects::class,
19+
],
20+
1221
/*
1322
|--------------------------------------------------------------------------
1423
| Laravel HTML
1524
|--------------------------------------------------------------------------
1625
|
1726
| This extends Laravel HTML.
1827
|
28+
| @doc https://foxws.nl/posts/wireuse/laravel-html
1929
| @doc https://spatie.be/docs/laravel-html/v3
2030
|
2131
*/
2232

2333
'html' => [
24-
'mixins' => [
25-
Html::class => HtmlExtendedMixin::class,
26-
BaseElement::class => BaseElementMixin::class,
27-
Elements\A::class => LinkElementMixin::class,
28-
],
34+
'mixins' => false,
2935
],
3036

3137
/*
@@ -35,11 +41,14 @@
3541
|
3642
| This controls structure discovery.
3743
|
44+
| @doc https://foxws.nl/posts/wireuse/structure-scout
3845
| @doc https://github.com/spatie/php-structure-discoverer
3946
|
4047
*/
4148

4249
'scout' => [
50+
'enabled' => false,
51+
4352
'cache_store' => null,
4453

4554
'cache_lifetime' => 60 * 60 * 24 * 7,

src/WireUseServiceProvider.php

+42-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
namespace Foxws\WireUse;
44

5+
use Composer\InstalledVersions;
56
use Foxws\WireUse\Scout\ComponentScout;
67
use Foxws\WireUse\Scout\LivewireScout;
8+
use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin;
9+
use Foxws\WireUse\Support\Html\Mixins\HtmlExtendedMixin;
10+
use Foxws\WireUse\Support\Html\Mixins\LinkElementMixin;
711
use Spatie\LaravelPackageTools\Package;
812
use Spatie\LaravelPackageTools\PackageServiceProvider;
913

@@ -18,8 +22,9 @@ public function configurePackage(Package $package): void
1822

1923
public function packageRegistered(): void
2024
{
21-
$this->app->singleton(ComponentScout::class, fn () => new ComponentScout);
22-
$this->app->singleton(LivewireScout::class, fn () => new LivewireScout);
25+
if (config('wireuse.scout.enabled', false)) {
26+
$this->registerStructureDiscovery();
27+
}
2328
}
2429

2530
public function packageBooted(): void
@@ -31,9 +36,9 @@ public function packageBooted(): void
3136

3237
protected function registerFeatures(): static
3338
{
34-
foreach ([
35-
\Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class,
36-
] as $feature) {
39+
$features = config('wireuse.features', []);
40+
41+
foreach ($features as $feature) {
3742
app('livewire')->componentHook($feature);
3843
}
3944

@@ -42,7 +47,38 @@ protected function registerFeatures(): static
4247

4348
protected function registerMixins(): static
4449
{
45-
foreach (config('wireuse.html.mixins', []) as $element => $mixin) {
50+
if (config('wireuse.html.mixins', false)) {
51+
$this->registerHtmlMixins();
52+
}
53+
54+
return $this;
55+
}
56+
57+
protected function registerStructureDiscovery(): static
58+
{
59+
if (! InstalledVersions::isInstalled('spatie/php-structure-discoverer')) {
60+
abort(500, 'The spatie/php-structure-discoverer package is required to use the Structure Discovery.');
61+
}
62+
63+
$this->app->singleton(ComponentScout::class, fn () => new ComponentScout);
64+
$this->app->singleton(LivewireScout::class, fn () => new LivewireScout);
65+
66+
return $this;
67+
}
68+
69+
protected function registerHtmlMixins(): static
70+
{
71+
if (! InstalledVersions::isInstalled('spatie/laravel-html')) {
72+
abort(500, 'The spatie/laravel-html package is required to use the HTML mixins.');
73+
}
74+
75+
$mixins = [
76+
\Spatie\Html\Html::class => HtmlExtendedMixin::class,
77+
\Spatie\Html\BaseElement::class => BaseElementMixin::class,
78+
\Spatie\Html\Elements\A::class => LinkElementMixin::class,
79+
];
80+
81+
foreach ($mixins as $element => $mixin) {
4682
$element::mixin(new $mixin);
4783
}
4884

0 commit comments

Comments
 (0)