name('filament') ->hasCommands([ AssetsCommand::class, CheckTranslationsCommand::class, FilamentAboutCommand::class, InstallCommand::class, MakeIssueCommand::class, MakeIssueCommandAlias::class, OptimizeClearCommand::class, OptimizeCommand::class, UpgradeCommand::class, ]) ->hasConfigFile() ->hasTranslations() ->hasViews(); } public function packageBooted(): void { FilamentAsset::register([ Css::make('support', __DIR__ . '/../dist/index.css'), Js::make('support', __DIR__ . '/../dist/index.js'), ], 'filament/support'); Blade::directive('captureSlots', function (string $expression): string { return "mapWithKeys(fn (string \$slot): array => [\$slot => \$slotContents[\$slot] ?? null])->all(); unset(\$slotContents) ?>"; }); Blade::directive('filamentScripts', function (string $expression): string { return ""; }); Blade::directive('filamentStyles', function (string $expression): string { return ""; }); Blade::extend(function ($view) { return preg_replace('/\s*@trim\s*/m', '', $view); }); Str::macro('sanitizeHtml', function (string $html): string { return app(HtmlSanitizerInterface::class)->sanitize($html); }); Stringable::macro('sanitizeHtml', function (): Stringable { /** @phpstan-ignore-next-line */ return new Stringable(Str::sanitizeHtml($this->value)); }); Str::macro('ucwords', function (string $value): string { return implode(' ', array_map( [Str::class, 'ucfirst'], explode(' ', $value), )); }); Stringable::macro('ucwords', function (): Stringable { /** @phpstan-ignore-next-line */ return new Stringable(Str::ucwords($this->value)); }); if (class_exists(InstalledVersions::class)) { $packages = [ 'filament', 'forms', 'notifications', 'support', 'tables', ]; AboutCommand::add('Filament', static fn () => [ 'Version' => InstalledVersions::getPrettyVersion('filament/support'), 'Packages' => collect($packages) ->filter(fn (string $package): bool => InstalledVersions::isInstalled("filament/{$package}")) ->join(', '), 'Views' => function () use ($packages): string { $publishedViewPaths = collect($packages) ->filter(fn (string $package): bool => is_dir(resource_path("views/vendor/{$package}"))); if (! $publishedViewPaths->count()) { return 'NOT PUBLISHED'; } return "PUBLISHED: {$publishedViewPaths->join(', ')}"; }, 'Blade Icons' => function (): string { return File::exists(app()->bootstrapPath('cache/blade-icons.php')) ? 'CACHED' : 'NOT CACHED'; }, 'Panel Components' => function (): string { if (! class_exists(CacheComponentsCommand::class)) { return 'NOT AVAILABLE'; } $path = app()->bootstrapPath('cache/filament/panels'); return File::isDirectory($path) && ! File::isEmptyDirectory($path) ? 'CACHED' : 'NOT CACHED'; }, ]); } if ($this->app->runningInConsole()) { $this->publishes([ $this->package->basePath('/../config/filament.php') => config_path('filament.php'), ], 'filament-config'); if (method_exists($this, 'optimizes')) { $this->optimizes( optimize: 'filament:optimize', /** @phpstan-ignore-line */ clear: 'filament:optimize-clear', /** @phpstan-ignore-line */ key: 'filament', /** @phpstan-ignore-line */ ); } } } public function packageRegistered(): void { $this->app->scoped( AssetManager::class, fn () => new AssetManager, ); $this->app->scoped( ScopedComponentManager::class, fn () => $this->app->make(ComponentManager::class)->clone(), ); $this->app->booted(fn () => ComponentManager::resolveScoped()); class_exists(RequestReceived::class) && Event::listen(RequestReceived::class, fn () => ComponentManager::resolveScoped()); $this->app->scoped( ColorManager::class, fn () => new ColorManager, ); $this->app->scoped( IconManager::class, fn () => new IconManager, ); $this->app->scoped( ViewManager::class, fn () => new ViewManager, ); $this->app->scoped( HtmlSanitizerInterface::class, fn (): HtmlSanitizer => new HtmlSanitizer( (new HtmlSanitizerConfig) ->allowSafeElements() ->allowRelativeLinks() ->allowRelativeMedias() ->allowAttribute('class', allowedElements: '*') ->allowAttribute('style', allowedElements: '*') ->withMaxInputLength(500000), ), ); } }