*/ final class CreateRange implements Action { public function __construct( protected readonly StorageService $storageService, protected readonly PublicS3Disk $s3Disk, protected readonly ImageOptimizerService $imageOptimizerService, ) { } /** * @param \App\Cqs\Actions\Ranges\CreateRangeInput $input */ #[\Override] public function __invoke(ActionInput $input): Range { Assert::isInstanceOf($input, CreateRangeInput::class); $attributes = [ 'name' => $input->name, 'description' => $input->description, 'picture_alt' => $input->pictureMetadata->alt ?? '', 'picture_title' => $input->pictureMetadata->title ?? '', 'status' => $input->status, ]; if ($input->picture instanceof UploadedFile) { $attributes['picture'] = $this->storeFile($input->picture); } $range = new Range(); $range->fill($attributes); $range->saveOrFail(); return $range; } protected function storeFile(UploadedFile $file): StorageFilePath { $optimized = $this->imageOptimizerService->optimize($file); return $this->storageService->storeFileOntoDisk($optimized, $this->s3Disk->disk); } }