Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ static function boot()
{
$instance = new static;

$instance->registerAssetDirective();
$instance->registerAssetRoutes();
}

public function registerAssetDirective()
public static function registerAssetDirective()
{
Blade::directive('fluxScripts', function ($expression) {
return <<<PHP
Expand Down
59 changes: 37 additions & 22 deletions src/FluxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,75 @@ public function register(): void

public function boot(): void
{
$this->bootComponentPath();
$this->bootFallbackBlazeDirectivesIfBlazeIsNotInstalled();
$this->bootTagCompiler();
$this->bootMacros();
$this->callAfterResolving('blade.compiler', function ($blade) {
$this->bootComponentPath($blade);
$this->bootFallbackBlazeDirectivesIfBlazeIsNotInstalled($blade);
$this->bootTagCompiler($blade);

app('livewire')->propertySynthesizer(DateRangeSynth::class);
AssetManager::registerAssetDirective();
});

AssetManager::boot();

app('flux')->boot();
$this->app->booted(function () {
$this->bootMacros();

app('livewire')->propertySynthesizer(DateRangeSynth::class);

app('flux')->boot();
});

$this->bootCommands();
}

public function bootComponentPath()
public function bootComponentPath($blade)
{
if (file_exists(resource_path('views/flux'))) {
Blade::anonymousComponentPath(resource_path('views/flux'), 'flux');
$blade->anonymousComponentPath(resource_path('views/flux'), 'flux');
}

Blade::anonymousComponentPath(__DIR__.'/../stubs/resources/views/flux', 'flux');
$blade->anonymousComponentPath(__DIR__.'/../stubs/resources/views/flux', 'flux');
}

public function bootFallbackBlazeDirectivesIfBlazeIsNotInstalled()
public function bootFallbackBlazeDirectivesIfBlazeIsNotInstalled($blade)
{
Blade::directive('blaze', fn () => '');
$blade->directive('blaze', fn () => '');

// `@pure` directive has been replaced with `@blaze` in Blaze v1.0, but we need to keep it here for
// backwards compatibility as people could have published components or custom icons using it...
Blade::directive('pure', fn () => '');
$blade->directive('pure', fn () => '');

Blade::directive('unblaze', function ($expression) {
$blade->directive('unblaze', function ($expression) {
return ''
. '<'.'?php $__getScope = fn($scope = []) => $scope; ?>'
. '<'.'?php if (isset($scope)) $__scope = $scope; ?>'
. '<'.'?php $scope = $__getScope('.$expression.'); ?>';
});

Blade::directive('endunblaze', function () {
$blade->directive('endunblaze', function () {
return '<'.'?php if (isset($__scope)) { $scope = $__scope; unset($__scope); } ?>';
});
}

public function bootTagCompiler()
public function bootTagCompiler($blade)
{
$compiler = new FluxTagCompiler(
app('blade.compiler')->getClassComponentAliases(),
app('blade.compiler')->getClassComponentNamespaces(),
app('blade.compiler')
);
$compiler = null;

$this->app->bind('flux.compiler', function () use (&$compiler, $blade) {
return $compiler ??= new FluxTagCompiler(
$blade->getClassComponentAliases(),
$blade->getClassComponentNamespaces(),
$blade
);
});

app()->bind('flux.compiler', fn () => $compiler);
$blade->precompiler(function ($in) use (&$compiler, $blade) {
$compiler ??= new FluxTagCompiler(
$blade->getClassComponentAliases(),
$blade->getClassComponentNamespaces(),
$blade
);

app('blade.compiler')->precompiler(function ($in) use ($compiler) {
return $compiler->compile($in);
});
}
Expand Down