Skip to content

Commit

Permalink
feat: check package installation (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Aug 6, 2024
1 parent 6470ab7 commit 104e0f4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 25 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
33 changes: 21 additions & 12 deletions config/wireuse.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
<?php

use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin;
use Foxws\WireUse\Support\Html\Mixins\HtmlExtendedMixin;
use Foxws\WireUse\Support\Html\Mixins\LinkElementMixin;
use Spatie\Html\BaseElement;
use Spatie\Html\Elements;
use Spatie\Html\Html;

return [

/*
|--------------------------------------------------------------------------
| Livewire Features
|--------------------------------------------------------------------------
|
| This controls Livewire component features.
|
| @doc https://foxws.nl/posts/wireuse/property-synthesizers
|
*/

'features' => [
// \Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class,
// \Foxws\WireUse\Support\Livewire\ModelStateObjects\SupportModelStateObjects::class,
],

/*
|--------------------------------------------------------------------------
| Laravel HTML
|--------------------------------------------------------------------------
|
| 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,
],

/*
Expand All @@ -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,
Expand Down
48 changes: 42 additions & 6 deletions src/WireUseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 104e0f4

Please sign in to comment.