Skip to content

Commit

Permalink
Add missing ServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusjp committed Oct 27, 2023
1 parent de8c350 commit 93f4d20
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/TypedConfigServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Coderg33k\TypedConfigGenerator;

use CoderG33k\Actions\GetClassForConfig;
use CoderG33k\Helper\DoesTypedConfigClassExist;
use Illuminate\Support\ServiceProvider;

final class TypedConfigServiceProvider extends ServiceProvider
{
public function register(): void
{
foreach (\array_keys(config()->all()) as $config) {
$doesConfigClassExist = DoesTypedConfigClassExist::determine(
namespace: $this->app->getNamespace(),
config: $config,
);

if (!$doesConfigClassExist) {
continue;
}

$class = GetClassForConfig::execute(
namespace: $this->app->getNamespace(),
config: $config,
);

$this->app->singleton(
$class,
fn () => $class::fromConfig(...config($config)),
);
}
}
}

0 comments on commit 93f4d20

Please sign in to comment.