mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-16 12:12:15 +01:00
Added import system
This commit is contained in:
37
app/Service/Import/Importers/ImporterProvider.php
Normal file
37
app/Service/Import/Importers/ImporterProvider.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Import\Importers;
|
||||
|
||||
class ImporterProvider
|
||||
{
|
||||
private array $importers = [
|
||||
'toggl_time_entries' => TogglTimeEntriesImporter::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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user