diff --git a/composer.json b/composer.json index a78e9986f..3064df270 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "illuminate/events": "^9.0", "illuminate/queue": "^9.0", "illuminate/support": "^9.23", + "rapidez/blade-directives": "^0.0.1", "tormjens/eventy": "^0.8" }, "require-dev": { diff --git a/src/RapidezServiceProvider.php b/src/RapidezServiceProvider.php index dc55a1dbb..55a23d0b5 100644 --- a/src/RapidezServiceProvider.php +++ b/src/RapidezServiceProvider.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Vite; use Illuminate\Support\ServiceProvider; +use Illuminate\View\ComponentAttributeBag; use Rapidez\Core\Commands\IndexProductsCommand; use Rapidez\Core\Commands\InstallCommand; use Rapidez\Core\Commands\InstallTestsCommand; @@ -29,6 +30,7 @@ public function boot() ->bootPublishables() ->bootRoutes() ->bootViews() + ->bootMacros() ->bootBladeComponents() ->bootMiddleware() ->bootTranslations(); @@ -44,7 +46,8 @@ public function register() $this ->registerConfigs() ->registerBindings() - ->registerThemes(); + ->registerThemes() + ->registerBladeDirectives(); } protected function bootCommands(): self @@ -134,6 +137,11 @@ protected function bootBladeComponents(): self { Blade::component('placeholder', PlaceholderComponent::class); + return $this; + } + + protected function registerBladeDirectives(): self + { Blade::directive('content', function ($expression) { return ""; }); @@ -157,6 +165,34 @@ protected function bootBladeComponents(): self return $this; } + protected function bootMacros(): self + { + /** + * @see https://github.com/laravel/framework/pull/47569 + * Check if the componentAttributeBag contains any of the keys. + * Usage: $attributes->hasAny(['href', ':href', "v-bind:href"]) + */ + ComponentAttributeBag::macro('hasAny', function ($key) + { + /** @var ComponentAttributeBag $this */ + if (!isset($this->attributes)) { + return false; + } + + $keys = is_array($key) ? $key : func_get_args(); + + foreach ($keys as $value) { + if ($this->has($value)) { + return true; + } + } + + return false; + }); + + return $this; + } + protected function bootMiddleware(): self { $this->app->make(Kernel::class)->pushMiddleware(DetermineAndSetShop::class);