mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 13:32:43 +01:00
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Import\Importers;
|
|
|
|
class ImporterProvider
|
|
{
|
|
/**
|
|
* @var array<string, class-string<ImporterContract>>
|
|
*/
|
|
private array $importers = [
|
|
'toggl_time_entries' => TogglTimeEntriesImporter::class,
|
|
'toggl_data_importer' => TogglDataImporter::class,
|
|
'clockify_time_entries' => ClockifyTimeEntriesImporter::class,
|
|
'clockify_projects' => ClockifyProjectsImporter::class,
|
|
];
|
|
|
|
/**
|
|
* @param class-string<ImporterContract> $importer
|
|
*/
|
|
public function registerImporter(string $type, string $importer): void
|
|
{
|
|
$this->importers[$type] = $importer;
|
|
}
|
|
|
|
/**
|
|
* @return array<string>
|
|
*/
|
|
public function getImporterKeys(): array
|
|
{
|
|
return array_keys($this->importers);
|
|
}
|
|
|
|
public function getImporter(string $type): ImporterContract
|
|
{
|
|
if (! array_key_exists($type, $this->importers)) {
|
|
throw new \InvalidArgumentException('Invalid importer type');
|
|
}
|
|
|
|
return new $this->importers[$type];
|
|
}
|
|
}
|