2026-03-04 15:56:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Service\Auth;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\Service\Access\AccessServicesFactory;
|
2026-03-13 11:31:33 +01:00
|
|
|
use MintyPHP\Service\Access\PermissionService;
|
2026-03-06 00:44:52 +01:00
|
|
|
use MintyPHP\Service\Settings\SettingsApiPolicyGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsAppGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
|
test(auth): add 33 unit tests for AuthService and RememberMeService
AuthServiceTest (17 tests): canLoginToTenant, refreshSessionAuthState,
loginUserById, login email-not-verified branch.
RememberMeServiceTest (16 tests): rememberUser, autoLoginFromCookie
(all 11 branches), forgetCurrentUser, forgetAllForUser,
expireAllTokensByAdmin.
Also fixes: 3 PHPStan errors in FrontendTelemetryIngestService,
8 CS-Fixer violations in out-of-scope files (ordered_imports,
braces_position).
All quality gates green: QG-001 (429 tests/0 failures),
QG-002 (0 errors), QG-003 (11 arch tests pass), QG-006 (0 violations).
Task: AUTH-LOGIN-REVIEW-001
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 11:43:31 +01:00
|
|
|
use MintyPHP\Service\Settings\SettingServicesFactory;
|
2026-03-10 22:48:10 +01:00
|
|
|
use MintyPHP\Service\Settings\SettingsLoginPersistenceGateway;
|
2026-03-06 00:44:52 +01:00
|
|
|
use MintyPHP\Service\Settings\SettingsMicrosoftGateway;
|
2026-03-04 15:56:58 +01:00
|
|
|
use MintyPHP\Service\Tenant\TenantScopeService;
|
|
|
|
|
|
|
|
|
|
class AuthGatewayFactory
|
|
|
|
|
{
|
2026-03-06 00:44:52 +01:00
|
|
|
private ?SettingsMicrosoftGateway $settingsMicrosoftGateway = null;
|
|
|
|
|
private ?SettingsApiPolicyGateway $settingsApiPolicyGateway = null;
|
|
|
|
|
private ?SettingsDefaultsGateway $settingsDefaultsGateway = null;
|
|
|
|
|
private ?SettingsAppGateway $settingsAppGateway = null;
|
2026-03-10 22:48:10 +01:00
|
|
|
private ?SettingsLoginPersistenceGateway $settingsLoginPersistenceGateway = null;
|
2026-03-13 11:31:33 +01:00
|
|
|
private ?PermissionService $permissionService = null;
|
2026-03-04 15:56:58 +01:00
|
|
|
private ?AuthSettingsGateway $authSettingsGateway = null;
|
|
|
|
|
private ?AuthTenantGateway $authTenantGateway = null;
|
|
|
|
|
private ?AuthCryptoGateway $authCryptoGateway = null;
|
|
|
|
|
private ?AuthExternalIdentityGateway $authExternalIdentityGateway = null;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly AuthRepositoryFactory $authRepositoryFactory,
|
|
|
|
|
private readonly AccessServicesFactory $accessServicesFactory,
|
|
|
|
|
private readonly SettingServicesFactory $settingServicesFactory,
|
|
|
|
|
private readonly TenantScopeService $tenantScopeService
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createAuthSettingsGateway(): AuthSettingsGateway
|
|
|
|
|
{
|
2026-03-06 00:44:52 +01:00
|
|
|
return $this->authSettingsGateway ??= new AuthSettingsGateway(
|
|
|
|
|
$this->createSettingsMicrosoftGateway(),
|
|
|
|
|
$this->createSettingsApiPolicyGateway(),
|
|
|
|
|
$this->createSettingsDefaultsGateway(),
|
2026-03-10 22:48:10 +01:00
|
|
|
$this->createSettingsAppGateway(),
|
|
|
|
|
$this->createSettingsLoginPersistenceGateway()
|
2026-03-06 00:44:52 +01:00
|
|
|
);
|
2026-03-04 15:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 11:31:33 +01:00
|
|
|
public function getTenantScopeService(): TenantScopeService
|
2026-03-04 15:56:58 +01:00
|
|
|
{
|
2026-03-13 11:31:33 +01:00
|
|
|
return $this->tenantScopeService;
|
2026-03-04 15:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 11:31:33 +01:00
|
|
|
public function createPermissionService(): PermissionService
|
2026-03-04 15:56:58 +01:00
|
|
|
{
|
2026-03-13 11:31:33 +01:00
|
|
|
return $this->permissionService ??= $this->accessServicesFactory->createPermissionService();
|
2026-03-04 15:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createAuthTenantGateway(): AuthTenantGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->authTenantGateway ??= new AuthTenantGateway(
|
|
|
|
|
$this->authRepositoryFactory->createTenantRepository()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createAuthCryptoGateway(): AuthCryptoGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->authCryptoGateway ??= new AuthCryptoGateway();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createAuthExternalIdentityGateway(): AuthExternalIdentityGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->authExternalIdentityGateway ??= new AuthExternalIdentityGateway(
|
|
|
|
|
$this->authRepositoryFactory->createUserExternalIdentityRepository()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 00:44:52 +01:00
|
|
|
private function createSettingsMicrosoftGateway(): SettingsMicrosoftGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->settingsMicrosoftGateway ??= $this->settingServicesFactory->createSettingsMicrosoftGateway();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createSettingsApiPolicyGateway(): SettingsApiPolicyGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->settingsApiPolicyGateway ??= $this->settingServicesFactory->createSettingsApiPolicyGateway();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createSettingsDefaultsGateway(): SettingsDefaultsGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->settingsDefaultsGateway ??= $this->settingServicesFactory->createSettingsDefaultsGateway();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createSettingsAppGateway(): SettingsAppGateway
|
2026-03-04 15:56:58 +01:00
|
|
|
{
|
2026-03-06 00:44:52 +01:00
|
|
|
return $this->settingsAppGateway ??= $this->settingServicesFactory->createSettingsAppGateway();
|
2026-03-04 15:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-10 22:48:10 +01:00
|
|
|
private function createSettingsLoginPersistenceGateway(): SettingsLoginPersistenceGateway
|
|
|
|
|
{
|
|
|
|
|
return $this->settingsLoginPersistenceGateway ??= $this->settingServicesFactory->createSettingsLoginPersistenceGateway();
|
|
|
|
|
}
|
2026-03-04 15:56:58 +01:00
|
|
|
}
|