36 lines
842 B
PHP
36 lines
842 B
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\File;
|
|
use App\Repository\FileRepository;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
class FileService
|
|
{
|
|
private Filesystem $fileSystem;
|
|
private string $bookFiles;
|
|
|
|
public function __construct(string $bookFiles, FileSystem $filesystem)
|
|
{
|
|
$this->bookFiles = $bookFiles;
|
|
$this->fileSystem = $filesystem;
|
|
}
|
|
|
|
/**
|
|
* @param File[] $files
|
|
* @return void
|
|
*/
|
|
public function removeFiles(Collection $files)
|
|
{
|
|
foreach ($files as $file) {
|
|
$filePath = $this->bookFiles . '/' . 'ebook_' . $file->getBook()->getId() . '_' .
|
|
md5($file->getFileName()) . '.' .
|
|
$file->getExtension();
|
|
|
|
$this->fileSystem->remove($filePath);
|
|
}
|
|
}
|
|
|
|
} |