/
AleksWork
/
diary_plants
Обзор
Документация
Войти
/
AleksWork
/
diary_plants
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Domain/Service/FileService.php
81 строка
2 KB
AlexeySerov
Add moveToGroup method in Plant Entity
07 май 2026, 18:23
07 май 2026, 18:23
b27fe01
Код
Авторство
О чём код?
<?php namespace App\Domain\Service; use Symfony\Component\HttpFoundation\File\File; use App\Infrastructure\Storage\LocalFileStorage; use Symfony\Component\HttpFoundation\File\UploadedFile; class FileService { public function __construct( private readonly LocalFileStorage $localFileStorage ) { } /** * @param string $directory * @return array */ public function getFilesInDirectory(string $directory): array { return $this->localFileStorage->getFilesInDirectory($directory); } /** * @param string $attachableType * @param int $attachableId * @return string */ public function getAttachmentsPath(string $attachableType, int $attachableId): string { $entity = explode('::', $attachableType); $entity = array_shift($entity); return ('attachments/' . $entity . '/' . $attachableId . '/'); } /** * @param UploadedFile $uploadedFile * @param string $directory * @param bool $moveFlag * @return File */ public function storeUploadedFile(UploadedFile $uploadedFile, string $directory, bool $moveFlag = true): File { return $this->localFileStorage->storeUploadedFile($uploadedFile, $directory, $moveFlag); } /** * @param string $directory * @param string $uuid * @param string $url * @return string */ public function getQrCodeLink(string $directory, string $uuid, string $url): string { return $this->localFileStorage->createQrCodeFile($directory, $uuid, $url); } /** * @param string $file * @return bool */ public function removeUploadedFile(string $file): bool { return $this->localFileStorage->removeUploadedFile($file); } /** * @param string $oldPath * @param int $newGroupId * @return string */ public function moveAttachmentQrFiles(string $oldPath, int $newGroupId): string { [$root, $type, $groupId, $plantId, $filename] = explode('/', $oldPath); $newPath = "{$root}/{$type}/{$newGroupId}/{$plantId}/{$filename}"; return $this->localFileStorage->move($oldPath, $newPath); } }