Skip to content

Commit

Permalink
Register ComponentManager if not registered
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jan 11, 2024
1 parent 1e0fcd7 commit 3a2b2a7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
17 changes: 17 additions & 0 deletions packages/support/src/Components/ComponentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ class ComponentManager
*/
protected array $methodCache = [];

final public function __construct() {}

public static function register(): void
{
app()->scopedIf(
static::class,
fn () => new static(),
);
}

public static function resolve(): static
{
static::register();

return app(static::class);
}

public function configureUsing(string $component, Closure $modifyUsing, ?Closure $during = null, bool $isImportant = false): mixed
{
if ($isImportant) {
Expand Down
2 changes: 1 addition & 1 deletion packages/support/src/Components/ViewComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function defaultView(string | Closure | null $view): static
*/
protected function extractPublicMethods(): array
{
return app(ComponentManager::class)->extractPublicMethods($this);
return ComponentManager::resolve()->extractPublicMethods($this);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/support/src/Concerns/Configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait Configurable
{
public static function configureUsing(Closure $modifyUsing, ?Closure $during = null, bool $isImportant = false): mixed
{
return app(ComponentManager::class)->configureUsing(
return ComponentManager::resolve()->configureUsing(
static::class,
$modifyUsing,
$during,
Expand All @@ -19,7 +19,7 @@ public static function configureUsing(Closure $modifyUsing, ?Closure $during = n

public function configure(): static
{
app(ComponentManager::class)->configure(
ComponentManager::resolve()->configure(
$this,
$this->setUp(...),
);
Expand Down
5 changes: 1 addition & 4 deletions packages/support/src/SupportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public function packageRegistered(): void
fn () => new AssetManager(),
);

$this->app->scoped(
ComponentManager::class,
fn () => new ComponentManager(),
);
ComponentManager::register();

$this->app->scoped(
ColorManager::class,
Expand Down

0 comments on commit 3a2b2a7

Please sign in to comment.