Files
breadcrumb-the-shire/lib/Service/Directory/DirectoryServicesFactory.php

85 lines
2.8 KiB
PHP
Raw Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Service\Directory;
2026-03-05 08:26:51 +01:00
use MintyPHP\Repository\Access\RoleRepositoryInterface;
use MintyPHP\Repository\Org\DepartmentRepositoryInterface;
use MintyPHP\Repository\Tenant\TenantRepositoryInterface;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\Access\RoleService;
use MintyPHP\Service\Audit\AuditRecorderInterface;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\Org\DepartmentService;
use MintyPHP\Service\Tenant\TenantScopeService;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\Tenant\TenantService;
use MintyPHP\Service\User\UserServicesFactory;
class DirectoryServicesFactory
{
private ?TenantService $tenantService = null;
private ?DepartmentService $departmentService = null;
private ?RoleService $roleService = null;
2026-03-04 15:56:58 +01:00
public function __construct(
private readonly UserServicesFactory $userServicesFactory,
private readonly AuditRecorderInterface $auditRecorder,
2026-03-04 15:56:58 +01:00
private readonly DirectoryRepositoryFactory $directoryRepositoryFactory,
private readonly DirectoryGatewayFactory $directoryGatewayFactory
2026-03-05 11:17:42 +01:00
) {
}
2026-02-23 12:58:19 +01:00
public function createTenantService(): TenantService
{
return $this->tenantService ??= new TenantService(
$this->createTenantRepository(),
$this->createDepartmentRepository(),
2026-03-04 15:56:58 +01:00
$this->createDirectorySettingsGateway(),
$this->auditRecorder
2026-02-23 12:58:19 +01:00
);
}
public function createDepartmentService(): DepartmentService
{
return $this->departmentService ??= new DepartmentService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory,
2026-02-23 12:58:19 +01:00
$this->createDepartmentRepository(),
$this->createDirectorySettingsGateway(),
$this->directoryGatewayFactory->getTenantScopeService(),
$this->auditRecorder
2026-02-23 12:58:19 +01:00
);
}
public function createRoleService(): RoleService
{
return $this->roleService ??= new RoleService(
$this->createRoleRepository(),
2026-03-04 15:56:58 +01:00
$this->createDirectorySettingsGateway(),
$this->auditRecorder
2026-02-23 12:58:19 +01:00
);
}
2026-03-06 00:44:52 +01:00
// Passthrough accessors so callers only need a reference to this factory, not the sub-factories.
2026-03-05 08:26:51 +01:00
public function createTenantRepository(): TenantRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->directoryRepositoryFactory->createTenantRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createDepartmentRepository(): DepartmentRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->directoryRepositoryFactory->createDepartmentRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createRoleRepository(): RoleRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->directoryRepositoryFactory->createRoleRepository();
2026-02-23 12:58:19 +01:00
}
public function createDirectorySettingsGateway(): DirectorySettingsGateway
{
2026-03-04 15:56:58 +01:00
return $this->directoryGatewayFactory->createDirectorySettingsGateway();
2026-02-23 12:58:19 +01:00
}
public function getTenantScopeService(): TenantScopeService
2026-02-23 12:58:19 +01:00
{
return $this->directoryGatewayFactory->getTenantScopeService();
2026-02-23 12:58:19 +01:00
}
}