PHPackages                             team-mate-pro/doctrine-utils-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. [Database &amp; ORM](/categories/database)
4. /
5. team-mate-pro/doctrine-utils-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

team-mate-pro/doctrine-utils-bundle
===================================

Doctrine utilities bundle for Team Mate Pro - handles file persistence and other Doctrine enhancements

1.1.0(1mo ago)02.0k↓21.7%MITPHPPHP &gt;=8.3

Since Nov 29Pushed 4mo agoCompare

[ Source](https://github.com/team-mate-pro/doctrine-utils-bundle)[ Packagist](https://packagist.org/packages/team-mate-pro/doctrine-utils-bundle)[ RSS](/packages/team-mate-pro-doctrine-utils-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (41)Versions (11)Used By (0)

Team Mate Pro Doctrine Utils Bundle
===================================

[](#team-mate-pro-doctrine-utils-bundle)

A Symfony bundle providing Doctrine utilities for file persistence with Flysystem storage backends.

Features
--------

[](#features)

- Automatic file upload to Flysystem storage on entity persist
- Automatic file deletion from storage on entity removal
- Automatic entity timestamping (createdAt/updatedAt)
- Configurable storage backends (local, S3, Azure, etc.)
- Enable/disable functionality via configuration
- Factory pattern for flexible entity integration
- Reusable entity traits (AutoIncrementIdTrait, UuidIdTrait)

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

[](#requirements)

- PHP 8.3+
- Symfony 7.0+
- Doctrine ORM 3.0+
- League Flysystem 3.0+

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

[](#installation)

```
composer require team-mate-pro/doctrine-utils-bundle
```

### Register the Bundle

[](#register-the-bundle)

If you're not using Symfony Flex, add the bundle to `config/bundles.php`:

```
return [
    // ...
    TeamMatePro\DoctrineUtilsBundle\TeamMateProDoctrineUtilsBundle::class => ['all' => true],
];
```

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

[](#configuration)

Create `config/packages/team_mate_pro_doctrine_utils.yaml`:

```
# Full configuration (copy-paste ready)
team_mate_pro_doctrine_utils:
    # Enable automatic file persistence on Doctrine entities
    enable_file_persistence: false

    # Flysystem storage service ID to use for file persistence
    storage_service: 'defaultStorage'

    # Enable automatic timestamping on entities implementing TimeStampAbleInterface
    enable_timestamp_listener: false
```

### Configuration Options

[](#configuration-options)

OptionTypeDefaultDescription`enable_file_persistence`boolean`false`Enable/disable the file persistence listener`storage_service`string`'defaultStorage'`Flysystem storage service ID`enable_timestamp_listener`boolean`false`Enable/disable the timestamp listenerSetup
-----

[](#setup)

### 1. Use the Built-in File Entity (Recommended)

[](#1-use-the-built-in-file-entity-recommended)

The bundle provides a ready-to-use `File` entity with UUID-based IDs:

```
use TeamMatePro\DoctrineUtilsBundle\Entity\File;

$file = new File(
    name: 'document.pdf',
    mime: 'application/pdf',
    bytes: filesize('/tmp/upload.pdf'),
    realPath: '/tmp/upload.pdf',
);

$entityManager->persist($file);
$entityManager->flush();
```

The built-in `File` entity:

- Uses `UuidIdTrait` for UUID-based primary keys
- Implements `FileInterface` from `team-mate-pro/contracts`
- Includes `isWebImage()` helper method
- Supports optional `fileUrl` for public URLs (S3, CDN, etc.)
- Provides `File::createFromUploadedFile(UploadedFile $file)` for Symfony file uploads
- Provides `File::createFromInterface(FileInterface $file)` for copying from other implementations

#### Register Doctrine Mapping for the Built-in Entity

[](#register-doctrine-mapping-for-the-built-in-entity)

To use the built-in `File` entity, you need to register its mapping in your Doctrine configuration.

Add to `config/packages/doctrine.yaml`:

```
doctrine:
    orm:
        mappings:
            TeamMateProDoctrineUtilsBundle:
                is_bundle: false
                type: attribute
                dir: '%kernel.project_dir%/vendor/team-mate-pro/doctrine-utils-bundle/src/Entity'
                prefix: 'TeamMatePro\DoctrineUtilsBundle\Entity'
                alias: DoctrineUtilsBundle
```

Then generate and run the migration:

```
# Generate migration for the files table
php bin/console doctrine:migrations:diff

# Review the generated migration, then run it
php bin/console doctrine:migrations:migrate
```

The migration will create the `files` table with the following structure:

ColumnTypeDescription`id`uuid (binary)Primary key (UUID v4)`name`varchar(255)Original filename`mime`varchar(100)MIME type`bytes`integerFile size in bytes`real_path`varchar(500)Path to the file on disk`created_at`datetime\_immutableCreation timestamp`file_url`varchar(500), nullablePublic URL (CDN, S3, etc.)### 2. Custom File Entity (Optional)

[](#2-custom-file-entity-optional)

If you need a custom entity, implement `TeamMatePro\Contracts\Model\FileInterface`:

```
