refactor(arch): enforce gateway compliance and remove service-wrapping gateways

This commit is contained in:
2026-03-13 11:31:33 +01:00
parent 082fa4c9a5
commit 892da0048d
96 changed files with 1117 additions and 1060 deletions

View File

@@ -8,8 +8,6 @@ use MintyPHP\Service\Tenant\TenantScopeService;
class DirectoryGatewayFactory
{
private ?DirectorySettingsGateway $directorySettingsGateway = null;
private ?DirectoryScopeGateway $directoryScopeGateway = null;
public function __construct(
private readonly SettingServicesFactory $settingServicesFactory,
private readonly TenantScopeService $tenantScopeService
@@ -23,8 +21,8 @@ class DirectoryGatewayFactory
);
}
public function createDirectoryScopeGateway(): DirectoryScopeGateway
public function getTenantScopeService(): TenantScopeService
{
return $this->directoryScopeGateway ??= new DirectoryScopeGateway($this->tenantScopeService);
return $this->tenantScopeService;
}
}

View File

@@ -1,58 +0,0 @@
<?php
namespace MintyPHP\Service\Directory;
use MintyPHP\Service\Tenant\TenantScopeService;
class DirectoryScopeGateway
{
public function __construct(
private readonly TenantScopeService $tenantScopeService
) {
}
public function hasGlobalAccess(int $userId): bool
{
return $this->tenantScopeService->hasGlobalAccess($userId);
}
public function getUserTenantIds(int $userId): array
{
return $this->tenantScopeService->getUserTenantIds($userId);
}
public function isStrict(): bool
{
return $this->tenantScopeService->isStrict();
}
public function canAccess(string $resourceType, int $resourceId, int $userId): bool
{
return $this->tenantScopeService->canAccess($resourceType, $resourceId, $userId);
}
public function resourceBelongsToTenant(string $resourceType, int $resourceId, int $tenantId): bool
{
return $this->tenantScopeService->resourceBelongsToTenant($resourceType, $resourceId, $tenantId);
}
public function filterTenantIdsForUser(array $tenantIds, int $userId): array
{
return $this->tenantScopeService->filterTenantIdsForUser($tenantIds, $userId);
}
// When a scoped admin updates tenant assignments, they can't see tenants outside their scope.
// This merges the requested IDs with any out-of-scope IDs from existing assignments so those
// aren't silently dropped when the admin saves.
public function mergeTenantIdsPreservingOutOfScope(
array $requestedTenantIds,
array $existingTenantIds,
array $allowedTenantIds
): array {
return $this->tenantScopeService->mergeTenantIdsPreservingOutOfScope(
$requestedTenantIds,
$existingTenantIds,
$allowedTenantIds
);
}
}

View File

@@ -8,6 +8,7 @@ use MintyPHP\Repository\Tenant\TenantRepositoryInterface;
use MintyPHP\Service\Access\RoleService;
use MintyPHP\Service\Audit\AuditServicesFactory;
use MintyPHP\Service\Org\DepartmentService;
use MintyPHP\Service\Tenant\TenantScopeService;
use MintyPHP\Service\Tenant\TenantService;
use MintyPHP\Service\User\UserServicesFactory;
@@ -41,7 +42,7 @@ class DirectoryServicesFactory
$this->userServicesFactory,
$this->createDepartmentRepository(),
$this->createDirectorySettingsGateway(),
$this->createDirectoryScopeGateway(),
$this->directoryGatewayFactory->getTenantScopeService(),
$this->auditServicesFactory->createSystemAuditService()
);
}
@@ -76,8 +77,8 @@ class DirectoryServicesFactory
return $this->directoryGatewayFactory->createDirectorySettingsGateway();
}
public function createDirectoryScopeGateway(): DirectoryScopeGateway
public function getTenantScopeService(): TenantScopeService
{
return $this->directoryGatewayFactory->createDirectoryScopeGateway();
return $this->directoryGatewayFactory->getTenantScopeService();
}
}