PHP code example of mikamatto / file-cleanup-bundle
1. Go to this page and download the library: Download mikamatto/file-cleanup-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mikamatto / file-cleanup-bundle example snippets
use Mikamatto\FileCleanupBundle\Contracts\FileBoundInterface;
class Video implements FileBoundInterface
{
public function getHandledFileTypes(): array
{
return ['image']; // Types of files this entity handles
}
public function getBoundFilesByType(string $type): array
{
if ($type !== 'image') {
return [];
}
$files = [];
if ($this->preview) {
$files[] = [
'path' => $this->preview,
'type' => 'preview'
];
}
if ($this->thumbnail) {
$files[] = [
'path' => $this->thumbnail,
'type' => 'thumb'
];
}
return $files;
}
public function getFileOwnerId(): int
{
return $this->id;
}
}
use Mikamatto\FileCleanupBundle\Contracts\FileManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
#[AutoconfigureTag('mikamatto_file_cleanup.manager')]
class ImageManager implements FileManagerInterface
{
public function getHandledType(): string
{
return 'image';
}
public function deleteFiles(array $files, int $ownerId): void
{
foreach ($files as $file) {
// Each file has 'path' and 'type'
$this->deleteFile($file['path'], $ownerId, $file['type']);
}
}
}