Files
project-minnesota/app/Services/MediaImporter.php

29 lines
854 B
PHP
Raw Normal View History

2024-06-01 03:10:49 +02:00
<?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");
}
}