mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-28 03:44:19 +08:00
Merge pull request #10947 from filamentphp/fix/configure-using-octane-boot
fix: configureUsing() in boot() on Octane
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
namespace Filament\Support\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\ScopedComponentManager;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
class ComponentManager
|
||||
class ComponentManager implements ScopedComponentManager
|
||||
{
|
||||
/**
|
||||
* @var array<class-string, array<Closure>>
|
||||
@@ -27,24 +28,23 @@ class ComponentManager
|
||||
{
|
||||
}
|
||||
|
||||
public static function isResolved(): bool
|
||||
public static function resolve(): ScopedComponentManager
|
||||
{
|
||||
return app()->resolved(static::class);
|
||||
if (app()->resolved(ScopedComponentManager::class)) {
|
||||
return static::resolveScoped();
|
||||
}
|
||||
|
||||
return app(ComponentManager::class);
|
||||
}
|
||||
|
||||
public static function register(): void
|
||||
public static function resolveScoped(): ScopedComponentManager
|
||||
{
|
||||
app()->scopedIf(
|
||||
static::class,
|
||||
fn () => new static(),
|
||||
);
|
||||
return app(ScopedComponentManager::class);
|
||||
}
|
||||
|
||||
public static function resolve(): static
|
||||
public function clone(): static
|
||||
{
|
||||
static::register();
|
||||
|
||||
return app(static::class);
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
public function configureUsing(string $component, Closure $modifyUsing, ?Closure $during = null, bool $isImportant = false): mixed
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Support\Components\Contracts;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Component;
|
||||
|
||||
interface ScopedComponentManager
|
||||
{
|
||||
public function configureUsing(string $component, Closure $modifyUsing, ?Closure $during = null, bool $isImportant = false): mixed;
|
||||
|
||||
public function configure(Component $component, Closure $setUp): void;
|
||||
|
||||
/**
|
||||
* @return array<string, Closure>
|
||||
*/
|
||||
public function extractPublicMethods(Component $component): array;
|
||||
}
|
||||
@@ -9,20 +9,6 @@ trait Configurable
|
||||
{
|
||||
public static function configureUsing(Closure $modifyUsing, ?Closure $during = null, bool $isImportant = false): mixed
|
||||
{
|
||||
if (! ($during || ComponentManager::isResolved())) {
|
||||
app()->resolving(
|
||||
ComponentManager::class,
|
||||
fn (ComponentManager $manager) => $manager->configureUsing(
|
||||
static::class,
|
||||
$modifyUsing,
|
||||
$during,
|
||||
$isImportant,
|
||||
),
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return ComponentManager::resolve()->configureUsing(
|
||||
static::class,
|
||||
$modifyUsing,
|
||||
|
||||
@@ -12,13 +12,16 @@ use Filament\Support\Commands\CheckTranslationsCommand;
|
||||
use Filament\Support\Commands\InstallCommand;
|
||||
use Filament\Support\Commands\UpgradeCommand;
|
||||
use Filament\Support\Components\ComponentManager;
|
||||
use Filament\Support\Components\Contracts\ScopedComponentManager;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Filament\Support\Icons\IconManager;
|
||||
use Filament\Support\View\ViewManager;
|
||||
use Illuminate\Foundation\Console\AboutCommand;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Stringable;
|
||||
use Laravel\Octane\Events\RequestReceived;
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
|
||||
@@ -49,7 +52,17 @@ class SupportServiceProvider extends PackageServiceProvider
|
||||
fn () => new AssetManager(),
|
||||
);
|
||||
|
||||
ComponentManager::register();
|
||||
$this->app->singleton(
|
||||
ComponentManager::class,
|
||||
fn () => new ComponentManager(),
|
||||
);
|
||||
|
||||
$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,
|
||||
|
||||
Reference in New Issue
Block a user