1
0
Files
breadcrumb-the-shire/lib/Service/Auth/AuthServicesFactory.php

146 lines
6.0 KiB
PHP
Raw Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Service\Auth;
2026-03-04 15:56:58 +01:00
use MintyPHP\Repository\Support\DatabaseSessionRepository;
use MintyPHP\Service\Audit\AuditServicesFactory;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\Mail\MailServicesFactory;
use MintyPHP\Service\User\UserServicesFactory;
class AuthServicesFactory
{
private ?TenantSsoService $tenantSsoService = null;
private ?MicrosoftOidcStateStoreService $microsoftOidcStateStoreService = null;
private ?MicrosoftOidcService $microsoftOidcService = null;
private ?ApiTokenService $apiTokenService = null;
private ?PasswordResetService $passwordResetService = null;
private ?EmailVerificationService $emailVerificationService = null;
private ?RememberMeService $rememberMeService = null;
private ?AuthService $authService = null;
private ?SsoUserLinkService $ssoUserLinkService = null;
2026-03-04 15:56:58 +01:00
public function __construct(
private readonly UserServicesFactory $userServicesFactory,
private readonly AuditServicesFactory $auditServicesFactory,
private readonly MailServicesFactory $mailServicesFactory,
private readonly AuthRepositoryFactory $authRepositoryFactory,
private readonly AuthGatewayFactory $authGatewayFactory,
private readonly DatabaseSessionRepository $databaseSessionRepository
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 createApiTokenService(): ApiTokenService
{
return $this->apiTokenService ??= new ApiTokenService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory->createUserReadRepository(),
$this->authRepositoryFactory->createApiTokenRepository(),
$this->authGatewayFactory->createAuthSettingsGateway(),
$this->createAuthScopeGateway(),
$this->databaseSessionRepository
2026-02-23 12:58:19 +01:00
);
}
public function createPasswordResetService(): PasswordResetService
{
return $this->passwordResetService ??= new PasswordResetService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory->createUserReadRepository(),
$this->authRepositoryFactory->createPasswordResetRepository(),
$this->userServicesFactory->createUserPasswordService(),
2026-02-23 12:58:19 +01:00
$this->createRememberMeService(),
2026-03-04 15:56:58 +01:00
$this->mailServicesFactory->createMailService()
2026-02-23 12:58:19 +01:00
);
}
public function createEmailVerificationService(): EmailVerificationService
{
return $this->emailVerificationService ??= new EmailVerificationService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory->createUserReadRepository(),
$this->userServicesFactory->createUserWriteRepository(),
$this->authRepositoryFactory->createEmailVerificationRepository(),
$this->mailServicesFactory->createMailService()
2026-02-23 12:58:19 +01:00
);
}
public function createRememberMeService(): RememberMeService
{
return $this->rememberMeService ??= new RememberMeService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory->createUserReadRepository(),
$this->userServicesFactory->createUserWriteRepository(),
$this->authRepositoryFactory->createRememberTokenRepository(),
$this->userServicesFactory->createUserTenantContextService(),
$this->authGatewayFactory->createAuthPermissionGateway(),
$this->authGatewayFactory->createAuthSavedFilterGateway()
2026-02-23 12:58:19 +01:00
);
}
public function createAuthService(): AuthService
{
return $this->authService ??= new AuthService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory->createUserReadRepository(),
$this->userServicesFactory->createUserWriteRepository(),
$this->userServicesFactory->createUserAccountService(),
$this->userServicesFactory->createUserTenantContextService(),
2026-02-23 12:58:19 +01:00
$this->createRememberMeService(),
$this->createEmailVerificationService(),
2026-03-04 15:56:58 +01:00
$this->authGatewayFactory->createAuthPermissionGateway(),
2026-02-23 12:58:19 +01:00
$this->createAuthTenantSsoGateway(),
2026-03-04 15:56:58 +01:00
$this->authGatewayFactory->createAuthSavedFilterGateway(),
$this->auditServicesFactory->createSystemAuditService()
2026-02-23 12:58:19 +01:00
);
}
public function createSsoUserLinkService(): SsoUserLinkService
{
return $this->ssoUserLinkService ??= new SsoUserLinkService(
2026-03-04 15:56:58 +01:00
$this->userServicesFactory->createUserReadRepository(),
$this->userServicesFactory->createUserWriteRepository(),
$this->userServicesFactory->createUserAssignmentService(),
$this->userServicesFactory->createUserTenantRepository(),
$this->authGatewayFactory->createAuthSettingsGateway(),
2026-02-23 12:58:19 +01:00
$this->createAuthTenantSsoGateway(),
2026-03-04 15:56:58 +01:00
$this->authGatewayFactory->createAuthAvatarGateway(),
$this->authGatewayFactory->createAuthExternalIdentityGateway()
2026-02-23 12:58:19 +01:00
);
}
public function createTenantSsoService(): TenantSsoService
{
return $this->tenantSsoService ??= new TenantSsoService(
2026-03-04 15:56:58 +01:00
$this->authGatewayFactory->createAuthTenantGateway(),
$this->authRepositoryFactory->createTenantMicrosoftAuthRepository(),
$this->authGatewayFactory->createAuthSettingsGateway(),
$this->authGatewayFactory->createAuthCryptoGateway()
2026-02-23 12:58:19 +01:00
);
}
public function createMicrosoftOidcStateStore(): MicrosoftOidcStateStoreService
{
return $this->microsoftOidcStateStoreService ??= new MicrosoftOidcStateStoreService();
}
public function createMicrosoftOidcService(): MicrosoftOidcService
{
return $this->microsoftOidcService ??= new MicrosoftOidcService(
$this->createTenantSsoService(),
2026-03-04 15:56:58 +01:00
$this->authGatewayFactory->createAuthTenantGateway(),
2026-02-23 12:58:19 +01:00
$this->createOidcHttpGateway(),
$this->createMicrosoftOidcStateStore()
);
}
public function createAuthScopeGateway(): AuthScopeGateway
{
2026-03-04 15:56:58 +01:00
return $this->authGatewayFactory->createAuthScopeGateway();
2026-02-23 12:58:19 +01:00
}
private function createAuthTenantSsoGateway(): AuthTenantSsoGateway
{
2026-03-04 15:56:58 +01:00
return $this->authGatewayFactory->createAuthTenantSsoGateway($this->createTenantSsoService());
2026-02-23 12:58:19 +01:00
}
private function createOidcHttpGateway(): OidcHttpGateway
{
2026-03-04 15:56:58 +01:00
return new OidcHttpGateway();
2026-02-23 12:58:19 +01:00
}
}