WIP
This commit is contained in:
29
app/Services/MediaImporter.php
Normal file
29
app/Services/MediaImporter.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\ImportsMedia;
|
||||
use App\Models\Album;
|
||||
use Illuminate\Foundation\Bus\PendingChain;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
|
||||
|
||||
class MediaImporter {
|
||||
private array $importers = [];
|
||||
|
||||
public function register(string $importer) : void {
|
||||
if(in_array(ImportsMedia::class, class_implements($importer))) {
|
||||
array_push($this->importers, $importer);
|
||||
}
|
||||
}
|
||||
|
||||
public function import(UploadedFile $file, Album $location): array {
|
||||
foreach ($this->importers as $importer) {
|
||||
if($importer::supports($file)) {
|
||||
return (new $importer($file, $location))->import();
|
||||
}
|
||||
}
|
||||
|
||||
throw new UnsupportedMediaTypeHttpException("The provided MediaType is not supported");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user