1
0
Files
breadcrumb-the-shire/lib/Service/Import/ImportServicesFactory.php

117 lines
4.5 KiB
PHP
Raw Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Service\Import;
2026-03-06 00:44:52 +01:00
use MintyPHP\Http\SessionStoreInterface;
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\PermissionService;
2026-02-23 12:58:19 +01:00
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;
2026-03-06 00:44:52 +01:00
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\Settings\SettingServicesFactory;
use MintyPHP\Service\Tenant\TenantScopeService;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\User\UserServicesFactory;
class ImportServicesFactory
{
private ?CsvReaderService $csvReaderService = null;
private ?ImportTempFileService $importTempFileService = null;
private ?ImportStateStoreService $importStateStoreService = null;
private ?ImportAuditService $importAuditService = null;
private ?PermissionService $permissionService = null;
2026-03-06 00:44:52 +01:00
private ?SettingsDefaultsGateway $settingsDefaultsGateway = null;
2026-02-23 12:58:19 +01:00
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,
2026-03-06 00:44:52 +01:00
private readonly ImportRepositoryFactory $importRepositoryFactory,
private readonly TenantScopeService $tenantScopeService,
2026-03-06 00:44:52 +01:00
private readonly SessionStoreInterface $sessionStore
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(
$this->userServicesFactory->createUserReadRepository(),
$this->directoryServicesFactory->createTenantRepository(),
$this->directoryServicesFactory->createRoleRepository(),
$this->directoryServicesFactory->createDepartmentRepository(),
),
$this->userServicesFactory->createUserAccountService()
),
'departments' => new DepartmentImportProfile(
new DepartmentImportGateway(
$this->directoryServicesFactory->createDepartmentRepository(),
$this->directoryServicesFactory->createTenantRepository()
),
2026-03-04 15:56:58 +01:00
$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->createPermissionService(),
2026-03-06 00:44:52 +01:00
$this->createSettingsDefaultsGateway(),
$this->tenantScopeService,
2026-03-06 00:44:52 +01:00
$this->sessionStore
2026-02-23 12:58:19 +01:00
);
}
public function createImportAuditService(): ImportAuditService
{
return $this->importAuditService ??= new ImportAuditService($this->getImportAuditRunRepository());
}
public function createImportStateStoreService(): ImportStateStoreService
{
2026-03-06 00:44:52 +01:00
return $this->importStateStoreService ??= new ImportStateStoreService(
$this->getImportTempFileService(),
$this->sessionStore
);
2026-02-23 12:58:19 +01:00
}
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 createPermissionService(): PermissionService
2026-02-23 12:58:19 +01:00
{
return $this->permissionService ??= $this->accessServicesFactory->createPermissionService();
2026-02-23 12:58:19 +01:00
}
2026-03-06 00:44:52 +01:00
private function createSettingsDefaultsGateway(): SettingsDefaultsGateway
2026-02-23 12:58:19 +01:00
{
2026-03-06 00:44:52 +01:00
return $this->settingsDefaultsGateway ??= $this->settingServicesFactory->createSettingsDefaultsGateway();
2026-02-23 12:58:19 +01:00
}
}