instances added god may help

This commit is contained in:
2026-02-23 12:58:19 +01:00
parent 25370a1a55
commit 99db252f60
290 changed files with 9858 additions and 4914 deletions

View File

@@ -0,0 +1,64 @@
<?php
namespace MintyPHP\Service\Directory;
use MintyPHP\Service\Tenant\TenantScopeService;
use MintyPHP\Service\Tenant\TenantServicesFactory;
class DirectoryScopeGateway
{
public function __construct(private readonly ?TenantScopeService $tenantScopeService = null)
{
}
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);
}
public function mergeTenantIdsPreservingOutOfScope(
array $requestedTenantIds,
array $existingTenantIds,
array $allowedTenantIds
): array {
return $this->tenantScopeService()->mergeTenantIdsPreservingOutOfScope(
$requestedTenantIds,
$existingTenantIds,
$allowedTenantIds
);
}
private function tenantScopeService(): TenantScopeService
{
if ($this->tenantScopeService instanceof TenantScopeService) {
return $this->tenantScopeService;
}
return (new TenantServicesFactory())->createTenantScopeService();
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace MintyPHP\Service\Directory;
use MintyPHP\Repository\Access\RoleRepository;
use MintyPHP\Repository\Org\DepartmentRepository;
use MintyPHP\Repository\Tenant\TenantRepository;
use MintyPHP\Service\Access\RoleService;
use MintyPHP\Service\Org\DepartmentService;
use MintyPHP\Service\Settings\SettingServicesFactory;
use MintyPHP\Service\Tenant\TenantServicesFactory;
use MintyPHP\Service\Tenant\TenantService;
use MintyPHP\Service\User\UserServicesFactory;
class DirectoryServicesFactory
{
private ?TenantRepository $tenantRepository = null;
private ?DepartmentRepository $departmentRepository = null;
private ?RoleRepository $roleRepository = null;
private ?DirectorySettingsGateway $directorySettingsGateway = null;
private ?DirectoryScopeGateway $directoryScopeGateway = null;
private ?TenantServicesFactory $tenantServicesFactory = null;
private ?TenantService $tenantService = null;
private ?DepartmentService $departmentService = null;
private ?RoleService $roleService = null;
private ?UserServicesFactory $userServicesFactory = null;
private ?SettingServicesFactory $settingServicesFactory = null;
public function createTenantService(): TenantService
{
return $this->tenantService ??= new TenantService(
$this->createTenantRepository(),
$this->createDepartmentRepository(),
$this->createDirectorySettingsGateway()
);
}
public function createDepartmentService(): DepartmentService
{
return $this->departmentService ??= new DepartmentService(
$this->createDepartmentRepository(),
$this->userServicesFactory(),
$this->createDirectorySettingsGateway(),
$this->createDirectoryScopeGateway()
);
}
public function createRoleService(): RoleService
{
return $this->roleService ??= new RoleService(
$this->createRoleRepository(),
$this->createDirectorySettingsGateway()
);
}
public function createTenantRepository(): TenantRepository
{
return $this->tenantRepository ??= new TenantRepository();
}
public function createDepartmentRepository(): DepartmentRepository
{
return $this->departmentRepository ??= new DepartmentRepository();
}
public function createRoleRepository(): RoleRepository
{
return $this->roleRepository ??= new RoleRepository();
}
public function createDirectorySettingsGateway(): DirectorySettingsGateway
{
return $this->directorySettingsGateway ??= new DirectorySettingsGateway(
$this->settingServicesFactory()->createSettingGateway()
);
}
public function createDirectoryScopeGateway(): DirectoryScopeGateway
{
return $this->directoryScopeGateway ??= new DirectoryScopeGateway(
$this->tenantServicesFactory()->createTenantScopeService()
);
}
private function userServicesFactory(): UserServicesFactory
{
return $this->userServicesFactory ??= new UserServicesFactory();
}
private function settingServicesFactory(): SettingServicesFactory
{
return $this->settingServicesFactory ??= new SettingServicesFactory();
}
private function tenantServicesFactory(): TenantServicesFactory
{
return $this->tenantServicesFactory ??= new TenantServicesFactory();
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace MintyPHP\Service\Directory;
use MintyPHP\Service\Settings\SettingGateway;
class DirectorySettingsGateway
{
public function __construct(private readonly SettingGateway $settingGateway)
{
}
public function setDefaultTenantId(?int $tenantId): void
{
$this->settingGateway->setDefaultTenantId($tenantId);
}
public function setDefaultDepartmentId(?int $departmentId): void
{
$this->settingGateway->setDefaultDepartmentId($departmentId);
}
public function setDefaultRoleId(?int $roleId): void
{
$this->settingGateway->setDefaultRoleId($roleId);
}
}