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

111 lines
4.3 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\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;
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\User\UserServicesFactory;
class ImportServicesFactory
{
private ?CsvReaderService $csvReaderService = null;
private ?ImportTempFileService $importTempFileService = null;
private ?ImportStateStoreService $importStateStoreService = null;
private ?ImportAuditService $importAuditService = null;
private ?PermissionGateway $permissionGateway = 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 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(
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(),
2026-03-06 00:44:52 +01:00
$this->createSettingsDefaultsGateway(),
$this->userServicesFactory->createUserScopeGateway(),
$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 createPermissionGateway(): PermissionGateway
{
2026-03-04 15:56:58 +01:00
return $this->permissionGateway ??= $this->accessServicesFactory->createPermissionGateway();
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
}
}