48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Registries;
|
|
|
|
use App\Enums\RegistryType;
|
|
use App\Models\Organisation;
|
|
use App\Models\Registry;
|
|
|
|
class RegistryResolver
|
|
{
|
|
public function __construct(
|
|
private readonly ManagedRegistryHealth $managedRegistryHealth,
|
|
) {}
|
|
|
|
public function buildRegistryFor(Organisation $organisation): ?Registry
|
|
{
|
|
$externalRegistry = $organisation->registries()
|
|
->where('type', '!=', RegistryType::MANAGED->value)
|
|
->first();
|
|
|
|
if ($externalRegistry instanceof Registry) {
|
|
return $externalRegistry;
|
|
}
|
|
|
|
$managedRegistry = $organisation->registries()
|
|
->where('type', RegistryType::MANAGED->value)
|
|
->first();
|
|
|
|
if ($managedRegistry instanceof Registry) {
|
|
return $this->managedRegistryHealth->readinessBlocker($managedRegistry) === null ? $managedRegistry : null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function managedRegistryBlockerFor(Organisation $organisation): ?string
|
|
{
|
|
$managedRegistry = $organisation->registries()
|
|
->where('type', RegistryType::MANAGED->value)
|
|
->with('controlServer')
|
|
->first();
|
|
|
|
return $managedRegistry instanceof Registry
|
|
? $this->managedRegistryHealth->readinessBlocker($managedRegistry)
|
|
: null;
|
|
}
|
|
}
|