108 lines
3.2 KiB
PHP
108 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Base;
|
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
|
|
final class ConfigResolver
|
|
{
|
|
private array $messages = [];
|
|
|
|
public function __construct(
|
|
#[Autowire(param: 'app.url')]
|
|
private readonly ?string $appUrl = null,
|
|
|
|
#[Autowire(param: 'app.debrid.real_debrid.key')]
|
|
private readonly ?string $realDebridApiKey = null,
|
|
|
|
#[Autowire(param: 'app.meta_provider.tmdb.key')]
|
|
private readonly ?string $tmdbApiKey = null,
|
|
|
|
#[Autowire(param: 'media.movies_path')]
|
|
private readonly ?string $moviesPath = null,
|
|
|
|
#[Autowire(param: 'media.tvshows.path')]
|
|
private readonly ?string $tvshowsPath = null,
|
|
|
|
#[Autowire(param: 'auth.method')]
|
|
private readonly ?string $authMethod = null,
|
|
|
|
#[Autowire(param: 'auth.oidc.well_known_url')]
|
|
private readonly ?string $authOidcWellKnownUrl = null,
|
|
|
|
#[Autowire(param: 'auth.oidc.client_id')]
|
|
private readonly ?string $authOidcClientId = null,
|
|
|
|
#[Autowire(param: 'auth.oidc.client_secret')]
|
|
private readonly ?string $authOidcClientSecret = null,
|
|
|
|
#[Autowire(param: 'auth.oidc.bypass_form_login')]
|
|
private ?bool $authOidcBypassFormLogin = null,
|
|
|
|
#[Autowire(param: 'notification.transport')]
|
|
private ?string $notificationTransport = null,
|
|
|
|
#[Autowire(param: 'notification.ntfy.dsn')]
|
|
private ?string $notificationNtfyDsn = null,
|
|
) {}
|
|
|
|
public function validate(): bool
|
|
{
|
|
$valid = true;
|
|
|
|
if (null === $this->realDebridApiKey || "" === $this->realDebridApiKey) {
|
|
$this->messages[] = "Your Real Debrid API key is missing. Please set it to the 'REAL_DEBRID_KEY' environment variable.";
|
|
$valid = false;
|
|
}
|
|
|
|
if (null === $this->tmdbApiKey || "" === $this->tmdbApiKey) {
|
|
$this->messages[] = "Your TMDB API key is missing. Please set it to the 'TMDB_API' environment variable.";
|
|
$valid = false;
|
|
}
|
|
|
|
if (null !== $this->notificationTransport) {
|
|
if (null === $this->notificationNtfyDsn || "" === $this->notificationNtfyDsn) {
|
|
$this->messages[] = "Your NOTIFICATION_TRANSPORT is set to 'ntfy' but you don't have the NTFY_DSN environment variable set.";
|
|
}
|
|
}
|
|
|
|
return $valid;
|
|
}
|
|
|
|
public function getMessages(): array
|
|
{
|
|
return $this->messages;
|
|
}
|
|
|
|
public function authIs(string $method): bool
|
|
{
|
|
if (strtolower($method) === strtolower($this->getAuthMethod())) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getAuthMethod(): string
|
|
{
|
|
return strtolower($this->authMethod);
|
|
}
|
|
|
|
public function bypassFormLogin(): bool
|
|
{
|
|
return $this->authOidcBypassFormLogin;
|
|
}
|
|
|
|
public function getAuthConfig(): array
|
|
{
|
|
return [
|
|
'method' => $this->authMethod,
|
|
'oidc' => [
|
|
'well_known_url' => $this->authOidcWellKnownUrl,
|
|
'client_id' => $this->authOidcClientId,
|
|
'client_secret' => $this->authOidcClientSecret,
|
|
'bypass_form_login' => $this->authOidcBypassFormLogin,
|
|
]
|
|
];
|
|
}
|
|
}
|