2026-02-23 12:58:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Service\Auth;
|
|
|
|
|
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 22:19:56 +01:00
|
|
|
use MintyPHP\App\AppContainer;
|
2026-03-19 18:20:13 +01:00
|
|
|
use MintyPHP\App\Module\ModuleEventDispatcher;
|
2026-03-06 00:44:52 +01:00
|
|
|
use MintyPHP\Http\CookieStoreInterface;
|
|
|
|
|
use MintyPHP\Http\RequestRuntimeInterface;
|
|
|
|
|
use MintyPHP\Http\SessionStoreInterface;
|
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-06 00:44:52 +01:00
|
|
|
private ?AuthSessionTenantContextService $authSessionTenantContextService = null;
|
2026-02-23 12:58:19 +01:00
|
|
|
|
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,
|
2026-03-06 00:44:52 +01:00
|
|
|
private readonly DatabaseSessionRepository $databaseSessionRepository,
|
|
|
|
|
private readonly SessionStoreInterface $sessionStore,
|
|
|
|
|
private readonly CookieStoreInterface $cookieStore,
|
2026-03-14 21:45:58 +01:00
|
|
|
private readonly RequestRuntimeInterface $requestRuntime,
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 22:19:56 +01:00
|
|
|
private readonly AppContainer $appContainer
|
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(),
|
2026-03-13 11:31:33 +01:00
|
|
|
$this->authGatewayFactory->getTenantScopeService(),
|
2026-03-06 00:44:52 +01:00
|
|
|
$this->databaseSessionRepository,
|
|
|
|
|
$this->requestRuntime
|
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(),
|
2026-03-13 11:31:33 +01:00
|
|
|
$this->authGatewayFactory->createPermissionService(),
|
2026-03-06 00:44:52 +01:00
|
|
|
$this->createAuthSessionTenantContextService(),
|
|
|
|
|
$this->sessionStore,
|
|
|
|
|
$this->cookieStore,
|
2026-03-10 22:48:10 +01:00
|
|
|
$this->requestRuntime,
|
2026-03-14 15:57:29 +01:00
|
|
|
$this->authGatewayFactory->createAuthSettingsGateway(),
|
|
|
|
|
new RememberMeRateLimiter()
|
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-13 11:31:33 +01:00
|
|
|
$this->authGatewayFactory->createPermissionService(),
|
|
|
|
|
$this->createTenantSsoService(),
|
2026-03-06 00:44:52 +01:00
|
|
|
$this->createAuthSessionTenantContextService(),
|
|
|
|
|
$this->auditServicesFactory->createSystemAuditService(),
|
2026-03-19 18:20:13 +01:00
|
|
|
$this->sessionStore,
|
|
|
|
|
$this->resolveEventDispatcher()
|
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-03-13 11:31:33 +01:00
|
|
|
$this->createTenantSsoService(),
|
|
|
|
|
$this->userServicesFactory->createUserAvatarService(),
|
2026-03-04 15:56:58 +01:00
|
|
|
$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
|
|
|
|
|
{
|
2026-03-06 00:44:52 +01:00
|
|
|
return $this->microsoftOidcStateStoreService ??= new MicrosoftOidcStateStoreService($this->sessionStore);
|
2026-02-23 12:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createOidcHttpGateway(): OidcHttpGateway
|
|
|
|
|
{
|
2026-03-04 15:56:58 +01:00
|
|
|
return new OidcHttpGateway();
|
2026-02-23 12:58:19 +01:00
|
|
|
}
|
2026-03-06 00:44:52 +01:00
|
|
|
|
2026-03-19 18:20:13 +01:00
|
|
|
private function resolveEventDispatcher(): ?ModuleEventDispatcher
|
|
|
|
|
{
|
|
|
|
|
if ($this->appContainer->has(ModuleEventDispatcher::class)) {
|
|
|
|
|
$dispatcher = $this->appContainer->get(ModuleEventDispatcher::class);
|
|
|
|
|
return $dispatcher instanceof ModuleEventDispatcher ? $dispatcher : null;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 00:44:52 +01:00
|
|
|
private function createAuthSessionTenantContextService(): AuthSessionTenantContextService
|
|
|
|
|
{
|
|
|
|
|
return $this->authSessionTenantContextService ??= new AuthSessionTenantContextService(
|
|
|
|
|
$this->userServicesFactory->createUserTenantContextService(),
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 22:19:56 +01:00
|
|
|
$this->sessionStore,
|
|
|
|
|
$this->appContainer
|
2026-03-06 00:44:52 +01:00
|
|
|
);
|
|
|
|
|
}
|
2026-02-23 12:58:19 +01:00
|
|
|
}
|