Files
breadcrumb-the-shire/core/Service/User/UserServicesFactory.php

164 lines
6.2 KiB
PHP
Raw Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Service\User;
use MintyPHP\App\Module\ModuleEventDispatcher;
2026-03-05 08:26:51 +01:00
use MintyPHP\Repository\Access\UserRoleRepositoryInterface;
use MintyPHP\Repository\Org\UserDepartmentRepositoryInterface;
2026-03-04 15:56:58 +01:00
use MintyPHP\Repository\Support\DatabaseSessionRepository;
2026-03-05 08:26:51 +01:00
use MintyPHP\Repository\Tenant\UserTenantRepositoryInterface;
use MintyPHP\Repository\User\UserListQueryRepositoryInterface;
use MintyPHP\Repository\User\UserReadRepositoryInterface;
use MintyPHP\Repository\User\UserWriteRepositoryInterface;
2026-03-13 21:11:48 +01:00
use MintyPHP\Service\Access\AssignableRoleService;
use MintyPHP\Service\Audit\AuditRecorderInterface;
use MintyPHP\Service\Audit\UserLifecycleAuditInterface;
2026-02-23 12:58:19 +01:00
class UserServicesFactory
{
private ?UserPasswordPolicyService $userPasswordPolicyService = null;
private ?UserPasswordService $userPasswordService = null;
private ?UserAvatarService $userAvatarService = null;
private ?UserAssignmentService $userAssignmentService = null;
private ?UserTenantContextService $userTenantContextService = null;
private ?UserAccountService $userAccountService = null;
private ?UserLifecycleService $userLifecycleService = null;
private ?UserLifecycleRestoreService $userLifecycleRestoreService = null;
2026-03-13 21:11:48 +01:00
/**
* @param \Closure(): AssignableRoleService $assignableRoleServiceFactory Lazy resolver to break circular dependency
*/
2026-03-04 15:56:58 +01:00
public function __construct(
private readonly AuditRecorderInterface $auditRecorder,
private readonly UserLifecycleAuditInterface $userLifecycleAudit,
2026-03-04 15:56:58 +01:00
private readonly UserRepositoryFactory $userRepositoryFactory,
private readonly UserGatewayFactory $userGatewayFactory,
2026-03-13 21:11:48 +01:00
private readonly DatabaseSessionRepository $databaseSessionRepository,
private readonly \Closure $assignableRoleServiceFactory,
private readonly ?ModuleEventDispatcher $eventDispatcher = null
2026-03-05 11:17:42 +01:00
) {
}
2026-03-04 15:56:58 +01:00
2026-02-23 12:58:19 +01:00
public function createUserAccountService(): UserAccountService
{
return $this->userAccountService ??= new UserAccountService(
$this->createUserReadRepository(),
$this->createUserWriteRepository(),
$this->createUserListQueryRepository(),
$this->createUserAssignmentService(),
$this->createUserPasswordService(),
$this->createUserSettingsGateway(),
$this->userGatewayFactory->getTenantScopeService(),
2026-03-04 15:56:58 +01:00
$this->createUserDirectoryGateway(),
$this->auditRecorder,
$this->databaseSessionRepository,
$this->eventDispatcher
2026-02-23 12:58:19 +01:00
);
}
public function createUserAssignmentService(): UserAssignmentService
{
return $this->userAssignmentService ??= new UserAssignmentService(
$this->createUserWriteRepository(),
$this->createUserTenantRepository(),
$this->createUserRoleRepository(),
$this->createUserDepartmentRepository(),
$this->createUserDirectoryGateway(),
$this->userGatewayFactory->createPermissionService(),
2026-03-13 21:11:48 +01:00
$this->databaseSessionRepository,
($this->assignableRoleServiceFactory)()
2026-02-23 12:58:19 +01:00
);
}
public function createUserTenantContextService(): UserTenantContextService
{
return $this->userTenantContextService ??= new UserTenantContextService(
$this->createUserReadRepository(),
$this->createUserWriteRepository(),
$this->createUserTenantRepository(),
$this->userGatewayFactory->getTenantScopeService(),
2026-02-23 12:58:19 +01:00
$this->createUserDirectoryGateway()
);
}
public function createUserPasswordService(): UserPasswordService
{
return $this->userPasswordService ??= new UserPasswordService(
$this->createUserPasswordPolicyService(),
$this->createUserWriteRepository()
);
}
public function createUserAvatarService(): UserAvatarService
{
return $this->userAvatarService ??= new UserAvatarService();
}
2026-03-05 08:26:51 +01:00
public function createUserReadRepository(): UserReadRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->userRepositoryFactory->createUserReadRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createUserWriteRepository(): UserWriteRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->userRepositoryFactory->createUserWriteRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createUserListQueryRepository(): UserListQueryRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->userRepositoryFactory->createUserListQueryRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createUserTenantRepository(): UserTenantRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->userRepositoryFactory->createUserTenantRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createUserRoleRepository(): UserRoleRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->userRepositoryFactory->createUserRoleRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
public function createUserDepartmentRepository(): UserDepartmentRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->userRepositoryFactory->createUserDepartmentRepository();
2026-02-23 12:58:19 +01:00
}
public function createUserPasswordPolicyService(): UserPasswordPolicyService
{
return $this->userPasswordPolicyService ??= new UserPasswordPolicyService();
}
public function createUserSettingsGateway(): UserSettingsGateway
{
2026-03-04 15:56:58 +01:00
return $this->userGatewayFactory->createUserSettingsGateway();
2026-02-23 12:58:19 +01:00
}
public function createUserDirectoryGateway(): UserDirectoryGateway
{
2026-03-04 15:56:58 +01:00
return $this->userGatewayFactory->createUserDirectoryGateway();
2026-02-23 12:58:19 +01:00
}
public function createUserLifecycleService(): UserLifecycleService
{
return $this->userLifecycleService ??= new UserLifecycleService(
$this->createUserReadRepository(),
$this->createUserWriteRepository(),
$this->createUserSettingsGateway(),
$this->userLifecycleAudit,
2026-03-04 15:56:58 +01:00
$this->databaseSessionRepository
2026-02-23 12:58:19 +01:00
);
}
public function createUserLifecycleRestoreService(): UserLifecycleRestoreService
{
return $this->userLifecycleRestoreService ??= new UserLifecycleRestoreService(
$this->createUserReadRepository(),
$this->createUserWriteRepository(),
$this->userLifecycleAudit,
$this->databaseSessionRepository,
$this->createUserSettingsGateway()
2026-02-23 12:58:19 +01:00
);
}
}