2026-02-23 12:58:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Service\Import;
|
|
|
|
|
|
2026-03-05 08:26:51 +01:00
|
|
|
use MintyPHP\Repository\Audit\ImportAuditRunRepositoryInterface;
|
2026-02-23 12:58:19 +01:00
|
|
|
use MintyPHP\Service\Access\AccessServicesFactory;
|
|
|
|
|
use MintyPHP\Service\Access\PermissionGateway;
|
|
|
|
|
use MintyPHP\Service\Audit\ImportAuditService;
|
2026-03-04 15:56:58 +01:00
|
|
|
use MintyPHP\Service\Directory\DirectoryServicesFactory;
|
2026-02-23 12:58:19 +01:00
|
|
|
use MintyPHP\Service\Import\Profile\DepartmentImportGateway;
|
|
|
|
|
use MintyPHP\Service\Import\Profile\DepartmentImportProfile;
|
|
|
|
|
use MintyPHP\Service\Import\Profile\UserImportGateway;
|
|
|
|
|
use MintyPHP\Service\Import\Profile\UserImportProfile;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingServicesFactory;
|
|
|
|
|
use MintyPHP\Service\User\UserServicesFactory;
|
|
|
|
|
|
|
|
|
|
class ImportServicesFactory
|
|
|
|
|
{
|
|
|
|
|
private ?CsvReaderService $csvReaderService = null;
|
|
|
|
|
private ?ImportTempFileService $importTempFileService = null;
|
|
|
|
|
private ?ImportStateStoreService $importStateStoreService = null;
|
|
|
|
|
private ?ImportAuditService $importAuditService = null;
|
|
|
|
|
private ?PermissionGateway $permissionGateway = null;
|
|
|
|
|
private ?SettingGateway $settingGateway = null;
|
|
|
|
|
private ?ImportService $importService = null;
|
2026-03-04 15:56:58 +01:00
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly UserServicesFactory $userServicesFactory,
|
|
|
|
|
private readonly AccessServicesFactory $accessServicesFactory,
|
|
|
|
|
private readonly SettingServicesFactory $settingServicesFactory,
|
|
|
|
|
private readonly DirectoryServicesFactory $directoryServicesFactory,
|
|
|
|
|
private readonly ImportRepositoryFactory $importRepositoryFactory
|
2026-03-05 11:17:42 +01:00
|
|
|
) {
|
|
|
|
|
}
|
2026-02-23 12:58:19 +01:00
|
|
|
|
|
|
|
|
public function createImportService(): ImportService
|
|
|
|
|
{
|
|
|
|
|
if ($this->importService !== null) {
|
|
|
|
|
return $this->importService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$profiles = [
|
|
|
|
|
'users' => new UserImportProfile(new UserImportGateway(
|
2026-03-04 15:56:58 +01:00
|
|
|
$this->userServicesFactory->createUserReadRepository(),
|
|
|
|
|
$this->userServicesFactory->createUserAccountService(),
|
2026-03-05 11:17:42 +01:00
|
|
|
$this->directoryServicesFactory->createTenantRepository(),
|
|
|
|
|
$this->directoryServicesFactory->createRoleRepository(),
|
|
|
|
|
$this->directoryServicesFactory->createDepartmentRepository(),
|
2026-03-04 15:56:58 +01:00
|
|
|
)),
|
|
|
|
|
'departments' => new DepartmentImportProfile(new DepartmentImportGateway(
|
|
|
|
|
$this->directoryServicesFactory->createDepartmentRepository(),
|
|
|
|
|
$this->directoryServicesFactory->createTenantRepository(),
|
|
|
|
|
$this->directoryServicesFactory->createDepartmentService()
|
2026-02-23 12:58:19 +01:00
|
|
|
)),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $this->importService = new ImportService(
|
|
|
|
|
$this->getCsvReaderService(),
|
|
|
|
|
$this->getImportTempFileService(),
|
|
|
|
|
$this->createImportAuditService(),
|
|
|
|
|
$this->createImportStateStoreService(),
|
|
|
|
|
$profiles,
|
|
|
|
|
$this->createPermissionGateway(),
|
|
|
|
|
$this->createSettingGateway(),
|
2026-03-04 15:56:58 +01:00
|
|
|
$this->userServicesFactory->createUserScopeGateway()
|
2026-02-23 12:58:19 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createImportAuditService(): ImportAuditService
|
|
|
|
|
{
|
|
|
|
|
return $this->importAuditService ??= new ImportAuditService($this->getImportAuditRunRepository());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createImportStateStoreService(): ImportStateStoreService
|
|
|
|
|
{
|
|
|
|
|
return $this->importStateStoreService ??= new ImportStateStoreService($this->getImportTempFileService());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getCsvReaderService(): CsvReaderService
|
|
|
|
|
{
|
|
|
|
|
return $this->csvReaderService ??= new CsvReaderService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getImportTempFileService(): ImportTempFileService
|
|
|
|
|
{
|
|
|
|
|
return $this->importTempFileService ??= new ImportTempFileService();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 08:26:51 +01:00
|
|
|
private function getImportAuditRunRepository(): ImportAuditRunRepositoryInterface
|
2026-02-23 12:58:19 +01:00
|
|
|
{
|
2026-03-04 15:56:58 +01:00
|
|
|
return $this->importRepositoryFactory->createImportAuditRunRepository();
|
2026-02-23 12:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createPermissionGateway(): PermissionGateway
|
|
|
|
|
{
|
2026-03-04 15:56:58 +01:00
|
|
|
return $this->permissionGateway ??= $this->accessServicesFactory->createPermissionGateway();
|
2026-02-23 12:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createSettingGateway(): SettingGateway
|
|
|
|
|
{
|
2026-03-04 15:56:58 +01:00
|
|
|
return $this->settingGateway ??= $this->settingServicesFactory->createSettingGateway();
|
2026-02-23 12:58:19 +01:00
|
|
|
}
|
|
|
|
|
}
|