Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Do not load Directives that conflict with other packages (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Aug 16, 2024
1 parent a58a9e2 commit c391f84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Directives/Directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ abstract class Directives implements DirectivesContract
*/
protected bool $registered = false;

/**
* Directives to not load when a conflicting class exists.
*/
protected array $conflicts = [];

/**
* Make an instance of the Directives.
*/
public static function make(): self
{
return new static();
return new static;
}

/**
Expand All @@ -31,9 +36,13 @@ public function register(): void
return;
}

foreach ($this->directives() as $function => $directive) {
Blade::directive($function, $directive);
}
$conflicts = collect($this->conflicts)
->filter(fn ($directives, $class) => class_exists($class))
->flatMap(fn ($directives) => (array) $directives);

collect($this->directives())
->except($conflicts)
->each(fn ($callback, $directive) => Blade::directive($directive, $callback));

$this->registered = true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Directives/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

class Helpers extends Directives
{
/**
* Directives to not load when a conflicting class exists.
*/
protected array $conflicts = [
'Livewire\Livewire' => ['script', 'endscript', 'js'],
];

/**
* The Helper directives.
*/
Expand Down

0 comments on commit c391f84

Please sign in to comment.