PHPackages                             2lenet/entity-file-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. 2lenet/entity-file-bundle

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

2lenet/entity-file-bundle
=========================

This package allows you to attach files to entities

1.2.4(2mo ago)316.1k↓28.1%1[1 PRs](https://github.com/2lenet/EntityFileBundle/pulls)1MITPHPPHP ^8.4CI passing

Since Jul 21Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/2lenet/EntityFileBundle)[ Packagist](https://packagist.org/packages/2lenet/entity-file-bundle)[ RSS](/packages/2lenet-entity-file-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (22)Used By (1)

EntityFileBundle
================

[](#entityfilebundle)

With this bundle, you can attach files to entities.

- [Installation](#installation)
- [Configuration](#configuration)
    - [Basic configuration](#basic-configuration)
    - [Change the storage adapter](#change-the-storage-adapter)
- [Usage](#usage)
    - [Retrieve files](#retrieve-files)
    - [Retrieve files from URL](#retrieve-files-from-url)
    - [Access file contents](#access-file-contents)
    - [Delete a file](#delete-a-file)
    - [Rename or move a file](#rename-or-move-a-file)
    - [Exception handling](#exception-handling)
- [Crudit](#crudit)

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

[](#installation)

```
composer require 2lenet/entity-file-bundle

```

Configuration
-------------

[](#configuration)

This bundle works with configurations. A configuration = 1 entity 1 file system.

For example, you may have a configuration for the logo of multiple sellers, and a configuration for the pictures of the products they sell.

### Basic configuration

[](#basic-configuration)

In `lle_entity_file.yaml`

```
lle_entity_file:
    configurations:
        seller_logos:
            class: "App\\Entity\\Seller"
            storage_adapter: "lle_entity_file.storage.default"
```

That's it! With the default storage adapter configuration, those files will be saved under data/seller\_logos

### Change the storage adapter

[](#change-the-storage-adapter)

This bundle uses the [FlySystem Symfony Bundle](https://flysystem.thephpleague.com/docs/). You can create your own storage adapters, (Local disk, FTP, Drive...).

For that, you need to [configure a new adapter](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/B-configuration-reference.md). Then, change the `storage_adapter` of your configuration.

Usage
-----

[](#usage)

First of all, you need to get the manager for your configuration. For that, use the `Lle\EntityFileBundle\Service\EntityFileLoader`

```
$manager = $entityFileLoader->get("seller_logos");
```

### Create a file

[](#create-a-file)

```
$manager = $entityFileLoader->get("seller_logos");

$entityFile = $manager->save($seller, $data, $path);

$this->em->persist($entityFile);
$this->em->flush();
```

$data may be a string, a Symfony File object (including UploadedFile) or a resource.

> ⚠️ **Never forget to persist and flush the EntityFile.**

- I want my EntityFile to contain additional properties!

You can use your own Entity class, it needs to be a Doctrine entity that implements `Lle\EntityFileBundle\Entity\EntityFileInterface`. For your convenience, the trait `LleEntityFileBundle\Entity\Trait\EntityFileTrait` exists.

You will also have to update your configuration:

```
unicorn:
    # ...
    entity_file_class: "App\\Entity\\UnicornEntityFile"
```

- I want to edit my new properties!

```
$manager = $entityFileLoader->get("unicorn");

$entityFile = $manager->save($seller, $data, "unicorn.png");

$entityFile->setDescription("Picture of a very sexy unicorn");
$this->em->persist($entityFile);
$this->em->flush();
```

- I want to have a dynamic path in my file structure!

```
$manager = $entityFileLoader->get("seller_logos");

$manager->save($order, $data, "you/can/do/this");

// example:

$dir = $order->getDate()->format("Y-m");
$name = $order->getId() . ".xml";

$manager->save($order, $data, $dir . "/" . $name)
```

- For some reason, I want to save my files somewhere else than data

Create your own storage adapter in `flysystem.yaml`, which is basically a copy of the default one with different directory option.

```
flysystem:
    storages:
        unicorn.storage:
            adapter: "local"
            options:
                directory: "%kernel.project_dir%/unicorns"
                permissions:
                    file:
                        public: 511
                        private: 511
                    dir:
                        public: 511
                        private: 511
```

### Retrieve files

[](#retrieve-files)

```
$manager = $entityFileLoader->get("seller_logos");

$manager->get($seller);
$manager->getOne($seller);
```

### Retrieve files from URL

[](#retrieve-files-from-url)

If you didn't use Symfony Flex, you need to add the routes in routes.yaml:

```
lle_entity_file:
    resource: "@LleEntityFileBundle/Resources/config/routes.yaml"
```

Two routes are available:

- lle\_entityfile\_entityfile\_read (requires configName and id)
    Example: /lle-entity-file/seller\_logos/1
- lle\_entityfile\_entityfile\_readbypath (requires configName and path)
    Example: /lle-entity-file/seller\_logos?path=2le.png

#### Protect your urls

[](#protect-your-urls)

By default, only logged in users can access those urls. You can change the `role` key in the configuration:

```
operation_reports:
    # ...
    role: "ROLE_OPERATOR"
```

- I want the files to be public !

You can use "PUBLIC\_ACCESS" in the `role` key.

- I want to do something more complex !

[Create a custom voter.](https://symfony.com/doc/current/security/voters.html)

#### Change content disposition (Show in browser or automatically download)

[](#change-content-disposition-show-in-browser-or-automatically-download)

By default, files are served inline. You can change the disposition key under your configuration:

```
zip_reports:
    # ...
    disposition: "attachment"
```

### Access file contents

[](#access-file-contents)

```
$manager = $entityFileLoader->get("seller_logos");

$manager->read($file);
$manager->readStream($file);
```

### Delete a file

[](#delete-a-file)

```
$manager = $entityFileLoader->get("seller_logos");

// deletes the entity and the actual file
$manager->delete($file);
```

### Rename or move a file

[](#rename-or-move-a-file)

```
$manager = $entityFileLoader->get("seller_logos");

$manager->move($file, "actually_not_an_unicorn.png");
$this->em->flush();
```

> ⚠️ **Never forget to flush the EntityFile.**

### Exception handling

[](#exception-handling)

Crudit
------

[](#crudit)

This bundle is compatible with 2LE's Crudit bundle.

You can use the EntityFileBrick, for example in tabs:

```
  public function getTabs(): array
  {
      return [
          "tab.files" => EntityFileBrickConfig::new("seller_logos"),
      ];
  }
```

It features a dropzone where you can see, add, remove and download files.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 58.8% 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

Every ~102 days

Recently: every ~25 days

Total

14

Last Release

67d ago

PHP version history (2 changes)1.0.1PHP ^8.1

1.2.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b715c92f6219caaeecb8f1a8d511ebfa17f05c2b868875dbefaaf95c0dd0df91?d=identicon)[sebheitzmann](/maintainers/sebheitzmann)

---

Top Contributors

[![SpaghettiBolognaise](https://avatars.githubusercontent.com/u/31731763?v=4)](https://github.com/SpaghettiBolognaise "SpaghettiBolognaise (40 commits)")[![valentin-helies](https://avatars.githubusercontent.com/u/89925635?v=4)](https://github.com/valentin-helies "valentin-helies (13 commits)")[![sebheitzmann](https://avatars.githubusercontent.com/u/2197902?v=4)](https://github.com/sebheitzmann "sebheitzmann (8 commits)")[![iBast](https://avatars.githubusercontent.com/u/77158590?v=4)](https://github.com/iBast "iBast (7 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/2lenet-entity-file-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[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)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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