PHPackages                             mikamatto/file-cleanup-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. mikamatto/file-cleanup-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

mikamatto/file-cleanup-bundle
=============================

Automatically cleans up files when their associated Doctrine entities are deleted

v1.0.0(1y ago)016PHPPHP &gt;=8.2

Since May 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mikamatto/MikamattoFileCleanupBundle)[ Packagist](https://packagist.org/packages/mikamatto/file-cleanup-bundle)[ RSS](/packages/mikamatto-file-cleanup-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

MikamattoFileCleanupBundle
==========================

[](#mikamattofilecleanupbundle)

Provides an infrastructure to streamline automatic file cleanup when Doctrine entities are deleted. The bundle abstracts the file management logic through a registry pattern, allowing applications to implement type-specific file managers while maintaining a clean separation of concerns.

Installation
------------

[](#installation)

```
composer require mikamatto/file-cleanup-bundle
```

Usage
-----

[](#usage)

### 1. Implement FileBoundInterface on your entity

[](#1-implement-fileboundinterface-on-your-entity)

```
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;
    }
}
```

### 2. Create a FileManager service

[](#2-create-a-filemanager-service)

```
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']);
        }
    }
}
```

How it works
------------

[](#how-it-works)

1. When an entity implementing `FileBoundInterface` is deleted:
    - The bundle's event subscriber is triggered
    - It gets the file types from `getHandledFileTypes()`
    - For each type, it finds the appropriate manager via `getHandledType()`
    - Gets the files to delete via `getBoundFilesByType()`
    - Passes the files to the manager's `deleteFiles()` method

The format of the files array returned by `getBoundFilesByType()` should match what your `FileManager` implementation expects. The bundle itself doesn't impose any specific structure. For example:

```
return [
    'preview' => [
        'path' => 'path/to/preview.jpg',
        'type' => 'preview'
    ],
    'thumb' => [
        'path' => 'path/to/thumb.jpg',
        'type' => 'thumb'
    ]
];
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Symfony 6.4 or higher

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance52

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

368d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b68bfb1904d505c75e0f3b866df0a96719bcb8268a7574ea249eb7cb76dd510?d=identicon)[mikamatto](/maintainers/mikamatto)

---

Top Contributors

[![mikamatto](https://avatars.githubusercontent.com/u/45991183?v=4)](https://github.com/mikamatto "mikamatto (1 commits)")

### Embed Badge

![Health badge](/badges/mikamatto-file-cleanup-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/mikamatto-file-cleanup-bundle/health.svg)](https://phpackages.com/packages/mikamatto-file-cleanup-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M309](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
