82 lines
3.4 KiB
PHP
82 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Infra\Providers;
|
|
|
|
use Application\Arcadia\Config\AppConfig;
|
|
use Application\Arcadia\Config\ThrottlingConfig;
|
|
use Application\Security\Config\DevClientCredentials;
|
|
use Application\Security\Config\HmacAuthConfig;
|
|
use Application\Security\Config\SecurityAlertMailConfig;
|
|
use Application\Security\Models\ValueObjects\ClientIdentifier;
|
|
use Application\Security\Models\ValueObjects\ClientName;
|
|
use Application\Security\Models\ValueObjects\ClientSecret;
|
|
use Application\Security\Models\ValueObjects\Entities\ClientId;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Infra\Config\ArcadiaStorageConfig;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Shared\ValueObjects\Config\AppName;
|
|
use Shared\ValueObjects\Config\AppTimezone;
|
|
use Shared\ValueObjects\Config\Locale;
|
|
use Shared\ValueObjects\Config\RequestsPerMinute;
|
|
use Shared\ValueObjects\Email;
|
|
|
|
final class ConfigServiceProvider extends ServiceProvider
|
|
{
|
|
#[\Override]
|
|
public function register(): void
|
|
{
|
|
$this->app->bind(SecurityAlertMailConfig::class, static function (): SecurityAlertMailConfig {
|
|
return new SecurityAlertMailConfig(
|
|
recipientEmail: new Email(Config::string('mail.security_recipient', 'security@example.com')),
|
|
);
|
|
});
|
|
|
|
$this->app->bind(HmacAuthConfig::class, static function (): HmacAuthConfig {
|
|
$allowDevBypass = Config::boolean('auth.hmac.allow_dev_bypass', false);
|
|
$devClient = null;
|
|
|
|
if (Config::has('auth.hmac.dev_client')) {
|
|
/** @var array{id: string, name: string, identifier: string, secret: string} $devClientConfig */
|
|
$devClientConfig = Config::array('auth.hmac.dev_client');
|
|
$devClient = new DevClientCredentials(
|
|
id: new ClientId(Uuid::fromString($devClientConfig['id'])),
|
|
name: new ClientName($devClientConfig['name']),
|
|
identifier: new ClientIdentifier($devClientConfig['identifier']),
|
|
secret: new ClientSecret($devClientConfig['secret']),
|
|
);
|
|
}
|
|
|
|
return new HmacAuthConfig(
|
|
allowDevBypass: $allowDevBypass,
|
|
devClient: $devClient,
|
|
);
|
|
});
|
|
|
|
$this->app->bind(ThrottlingConfig::class, static function (): ThrottlingConfig {
|
|
return new ThrottlingConfig(
|
|
webLimit: new RequestsPerMinute(Config::integer('throttles.web', 120)),
|
|
apiV1Limit: new RequestsPerMinute(Config::integer('throttles.api.v1', 60)),
|
|
);
|
|
});
|
|
|
|
$this->app->bind(AppConfig::class, static function (): AppConfig {
|
|
return new AppConfig(
|
|
name: new AppName(Config::string('app.name', 'Arcadia')),
|
|
timezone: new AppTimezone(Config::string('app.timezone', 'UTC')),
|
|
locale: new Locale(Config::string('app.locale', 'en')),
|
|
fallbackLocale: new Locale(Config::string('app.fallback_locale', 'en')),
|
|
isDebug: Config::boolean('app.debug', false),
|
|
);
|
|
});
|
|
|
|
$this->app->bind(ArcadiaStorageConfig::class, static function (): ArcadiaStorageConfig {
|
|
return new ArcadiaStorageConfig(
|
|
cacheStore: Config::string('cache.arcadia_store', 'database'),
|
|
databaseConnection: Config::string('database.arcadia_meta_model', 'arcadia'),
|
|
);
|
|
});
|
|
}
|
|
}
|