Move the entire audit subsystem (system audit, API audit, import audit, user lifecycle audit, frontend telemetry) from core into modules/audit/. Core decoupling via interface-based injection: - AuditRecorderInterface replaces SystemAuditService in 10+ core services - UserLifecycleAuditInterface / ImportAuditInterface for specialized flows - NullAuditRecorder fallback when audit module is disabled - ApiBootstrap/ApiResponse use null-safe callable resolvers Module structure (modules/audit/): - Manifest with routes, permissions, scheduler jobs, authorization policy - 9 services, 8 repositories, 6 domain enums, 4 job handlers - 33 page files, 4 JS files, 8 test files, migration scripts, i18n Core cleanup: - OperationsAuthorizationPolicy, UiCapabilityMap, PermissionService surgically cleaned of audit-specific constants - Sidebar template cleared of hardcoded audit navigation - AuditModuleIsolationContractTest ensures no future core→module coupling All quality gates pass: 1346 tests (19,276 assertions), PHPStan level 5 clean, architecture contracts verified. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
164 lines
6.2 KiB
PHP
164 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Service\User;
|
|
|
|
use MintyPHP\App\Module\ModuleEventDispatcher;
|
|
use MintyPHP\Repository\Access\UserRoleRepositoryInterface;
|
|
use MintyPHP\Repository\Org\UserDepartmentRepositoryInterface;
|
|
use MintyPHP\Repository\Support\DatabaseSessionRepository;
|
|
use MintyPHP\Repository\Tenant\UserTenantRepositoryInterface;
|
|
use MintyPHP\Repository\User\UserListQueryRepositoryInterface;
|
|
use MintyPHP\Repository\User\UserReadRepositoryInterface;
|
|
use MintyPHP\Repository\User\UserWriteRepositoryInterface;
|
|
use MintyPHP\Service\Access\AssignableRoleService;
|
|
use MintyPHP\Service\Audit\AuditRecorderInterface;
|
|
use MintyPHP\Service\Audit\UserLifecycleAuditInterface;
|
|
|
|
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;
|
|
|
|
/**
|
|
* @param \Closure(): AssignableRoleService $assignableRoleServiceFactory Lazy resolver to break circular dependency
|
|
*/
|
|
public function __construct(
|
|
private readonly AuditRecorderInterface $auditRecorder,
|
|
private readonly UserLifecycleAuditInterface $userLifecycleAudit,
|
|
private readonly UserRepositoryFactory $userRepositoryFactory,
|
|
private readonly UserGatewayFactory $userGatewayFactory,
|
|
private readonly DatabaseSessionRepository $databaseSessionRepository,
|
|
private readonly \Closure $assignableRoleServiceFactory,
|
|
private readonly ?ModuleEventDispatcher $eventDispatcher = null
|
|
) {
|
|
}
|
|
|
|
public function createUserAccountService(): UserAccountService
|
|
{
|
|
return $this->userAccountService ??= new UserAccountService(
|
|
$this->createUserReadRepository(),
|
|
$this->createUserWriteRepository(),
|
|
$this->createUserListQueryRepository(),
|
|
$this->createUserAssignmentService(),
|
|
$this->createUserPasswordService(),
|
|
$this->createUserSettingsGateway(),
|
|
$this->userGatewayFactory->getTenantScopeService(),
|
|
$this->createUserDirectoryGateway(),
|
|
$this->auditRecorder,
|
|
$this->databaseSessionRepository,
|
|
$this->eventDispatcher
|
|
);
|
|
}
|
|
|
|
public function createUserAssignmentService(): UserAssignmentService
|
|
{
|
|
return $this->userAssignmentService ??= new UserAssignmentService(
|
|
$this->createUserWriteRepository(),
|
|
$this->createUserTenantRepository(),
|
|
$this->createUserRoleRepository(),
|
|
$this->createUserDepartmentRepository(),
|
|
$this->createUserDirectoryGateway(),
|
|
$this->userGatewayFactory->createPermissionService(),
|
|
$this->databaseSessionRepository,
|
|
($this->assignableRoleServiceFactory)()
|
|
);
|
|
}
|
|
|
|
public function createUserTenantContextService(): UserTenantContextService
|
|
{
|
|
return $this->userTenantContextService ??= new UserTenantContextService(
|
|
$this->createUserReadRepository(),
|
|
$this->createUserWriteRepository(),
|
|
$this->createUserTenantRepository(),
|
|
$this->userGatewayFactory->getTenantScopeService(),
|
|
$this->createUserDirectoryGateway()
|
|
);
|
|
}
|
|
|
|
public function createUserPasswordService(): UserPasswordService
|
|
{
|
|
return $this->userPasswordService ??= new UserPasswordService(
|
|
$this->createUserPasswordPolicyService(),
|
|
$this->createUserWriteRepository()
|
|
);
|
|
}
|
|
|
|
public function createUserAvatarService(): UserAvatarService
|
|
{
|
|
return $this->userAvatarService ??= new UserAvatarService();
|
|
}
|
|
|
|
public function createUserReadRepository(): UserReadRepositoryInterface
|
|
{
|
|
return $this->userRepositoryFactory->createUserReadRepository();
|
|
}
|
|
|
|
public function createUserWriteRepository(): UserWriteRepositoryInterface
|
|
{
|
|
return $this->userRepositoryFactory->createUserWriteRepository();
|
|
}
|
|
|
|
public function createUserListQueryRepository(): UserListQueryRepositoryInterface
|
|
{
|
|
return $this->userRepositoryFactory->createUserListQueryRepository();
|
|
}
|
|
|
|
public function createUserTenantRepository(): UserTenantRepositoryInterface
|
|
{
|
|
return $this->userRepositoryFactory->createUserTenantRepository();
|
|
}
|
|
|
|
public function createUserRoleRepository(): UserRoleRepositoryInterface
|
|
{
|
|
return $this->userRepositoryFactory->createUserRoleRepository();
|
|
}
|
|
|
|
public function createUserDepartmentRepository(): UserDepartmentRepositoryInterface
|
|
{
|
|
return $this->userRepositoryFactory->createUserDepartmentRepository();
|
|
}
|
|
|
|
public function createUserPasswordPolicyService(): UserPasswordPolicyService
|
|
{
|
|
return $this->userPasswordPolicyService ??= new UserPasswordPolicyService();
|
|
}
|
|
|
|
public function createUserSettingsGateway(): UserSettingsGateway
|
|
{
|
|
return $this->userGatewayFactory->createUserSettingsGateway();
|
|
}
|
|
|
|
public function createUserDirectoryGateway(): UserDirectoryGateway
|
|
{
|
|
return $this->userGatewayFactory->createUserDirectoryGateway();
|
|
}
|
|
|
|
public function createUserLifecycleService(): UserLifecycleService
|
|
{
|
|
return $this->userLifecycleService ??= new UserLifecycleService(
|
|
$this->createUserReadRepository(),
|
|
$this->createUserWriteRepository(),
|
|
$this->createUserSettingsGateway(),
|
|
$this->userLifecycleAudit,
|
|
$this->databaseSessionRepository
|
|
);
|
|
}
|
|
|
|
public function createUserLifecycleRestoreService(): UserLifecycleRestoreService
|
|
{
|
|
return $this->userLifecycleRestoreService ??= new UserLifecycleRestoreService(
|
|
$this->createUserReadRepository(),
|
|
$this->createUserWriteRepository(),
|
|
$this->userLifecycleAudit,
|
|
$this->databaseSessionRepository,
|
|
$this->createUserSettingsGateway()
|
|
);
|
|
}
|
|
}
|