*/ class DeleteMediaFileHandler implements HandlerInterface { public function __construct( private readonly DownloadRepository $downloadRepository, private readonly MediaFiles $mediaFiles, ) {} public function handle(CommandInterface $command): ResultInterface { /** @var Download $downloadRecord */ $downloadRecord = $this->downloadRepository->find($command->downloadId); $filepath = $this->getFullFilepath($downloadRecord); $result = $this->mediaFiles->removeFile($filepath); return new DeleteMediaFileResult( message: true === $result ? 'File removed' : 'File not removed', filepath: $filepath, isDeleted: $result ); } private function getFullFilepath(Download $download): string { return $this->mediaFiles->getPathByType($download->getMediaType()) . DIRECTORY_SEPARATOR . $download->getFilename(); } }