PHPackages                             headsnet/doctrine-tools-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. headsnet/doctrine-tools-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

headsnet/doctrine-tools-bundle
==============================

Tools and helpers for using Doctrine in larger Symfony projects

v0.3.4(5mo ago)218.1k↓44.6%1[2 PRs](https://github.com/headsnet/doctrine-tools-bundle/pulls)MITPHPPHP &gt;=8.2CI passing

Since May 23Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/headsnet/doctrine-tools-bundle)[ Packagist](https://packagist.org/packages/headsnet/doctrine-tools-bundle)[ Docs](https://github.com/headsnet/doctrine-tools-bundle)[ RSS](/packages/headsnet-doctrine-tools-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (12)Versions (14)Used By (0)

Doctrine Tools for Symfony
==========================

[](#doctrine-tools-for-symfony)

[![Build Status](https://github.com/headsnet/doctrine-tools-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/headsnet/doctrine-tools-bundle/actions/workflows/ci.yml/badge.svg)[![Coverage](https://raw.githubusercontent.com/headsnet/doctrine-tools-bundle/image-data/coverage.svg)](https://raw.githubusercontent.com/headsnet/doctrine-tools-bundle/image-data/coverage.svg)[![Latest Stable Version](https://camo.githubusercontent.com/2e42bdf52583f5a2b0f56b86e79da6f91f0731bf220d61eef699436e5c280896/68747470733a2f2f706f7365722e707567782e6f72672f68656164736e65742f646f637472696e652d746f6f6c732d62756e646c652f76)](//packagist.org/packages/headsnet/doctrine-tools-bundle)[![Total Downloads](https://camo.githubusercontent.com/cedd8027c0f4a444fb41b65386f461be067ed0588d411cf267292439976f4a37/68747470733a2f2f706f7365722e707567782e6f72672f68656164736e65742f646f637472696e652d746f6f6c732d62756e646c652f646f776e6c6f616473)](//packagist.org/packages/headsnet/doctrine-tools-bundle)[![License](https://camo.githubusercontent.com/b47c3aaf8831dabbead23f88a6a6d9cb4cf9b84b09087e5f7fbf50376946e036/68747470733a2f2f706f7365722e707567782e6f72672f68656164736e65742f646f637472696e652d746f6f6c732d62756e646c652f6c6963656e7365)](//packagist.org/packages/headsnet/doctrine-tools-bundle)[![PHP Version Require](https://camo.githubusercontent.com/228f030cdabbc4a6c2b12b85a4115829d6ec89de727ecffd7e94622c384b681e/687474703a2f2f706f7365722e707567782e6f72672f68656164736e65742f646f637472696e652d746f6f6c732d62756e646c652f726571756972652f706870)](//packagist.org/packages/headsnet/doctrine-tools-bundle)

Various tools and helpers for using Doctrine ORM in larger Symfony projects.

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

[](#installation)

```
composer require headsnet/doctrine-tools-bundle
```

If your Symfony installation does not auto-register bundles, add it manually:

```
// bundles.php
return [
    ...
    Headsnet\DoctrineToolsBundle\HeadsnetDoctrineToolsBundle::class => ['all' => true],
];
```

Features
--------

[](#features)

- [Dynamically Create Types For Standard Objects](#dynamically-create-types-for-standard-objects)
- [Auto-Register Custom Doctrine Type Mappings](#auto-register-custom-doctrine-type-mappings)
- [Auto-Register Carbon Doctrine Type Mappings](#auto-register-carbon-datetime-type-mappings)

### Dynamically Create Types For Standard Objects

[](#dynamically-create-types-for-standard-objects)

Applying the `#[DoctrineType]` attribute to a class will generate a Doctrine mapping type for the object and register it in the application. To configure this behaviour, you must specify where to look for the classes to auto-register.

```
headsnet_doctrine_tools:
  root_namespace: Headsnet\DoctrineToolsBundle
  custom_types:
    scan_dirs:
      - 'src/' # the default value
```

Currently the bundle supports the following standard types:

- `string` via `AbstractStringMappingType`
- `integer` via `AbstractIntegerMappingType`
- `uuid` via `AbstractUuidMappingType`

For example, we have a string backed value object:

```
namespace App\Domain\Model;

use Headsnet\DoctrineToolsBundle\Attribute\DoctrineType;

#[DoctrineType(name: 'person_name', type: 'string')]
class PersonName
{
    public function __construct(
        private readonly string $value
    ) {
    }

    public static function create(string $value): self
    {
        return new self($value);
    }

    public function asString(): string
    {
        return $this->value;
    }
}
```

This will cause a PHP file to be generated that provides the Doctrine Mapping Type for the class - something like:

```
class PersonNameType extends \Headsnet\DoctrineToolsBundle\Types\StandardTypes\AbstractStringMappingType {
    public function getName(): string
    {
        return 'person_name';
    }

    public function getClass(): string
    {
        return 'App\Domain\Model\PersonName';
    }
}
```

This file is created in `src/_generated/` - you will want to add this directory to your `.gitignore` file.

### Auto-Register Custom Doctrine Type Mappings

[](#auto-register-custom-doctrine-type-mappings)

The bundle can auto-register custom Doctrine DBAL types, eliminating the need to specify them all in `config/packages/doctrine.yaml`:

Define the directories to scan for Doctrine types:

```
headsnet_doctrine_tools:
  custom_mappings:
    scan_dirs:
      - 'src/Infra/Persistence/DBAL/Types'
```

Then add the `#[DoctrineTypeMapping]` attribute to the custom type class:

```
use Doctrine\DBAL\Types\Type;
use Headsnet\DoctrineToolsBundle\Attribute\DoctrineMappingType;

#[DoctrineTypeMapping]
final class ReservationIdType extends Type
{
    // defines "reservation_id" type
}
```

This will register a custom type based on the class name - in this case the custom column type will be called `reservation_id`.

To customise the type name, specify it in the `#[DoctrineTypeMapping]` attribute. The following will register a type called `my_reservation_id`.

```
#[DoctrineTypeMapping(name: 'my_reservation_id')]
final class ReservationIdType extends Type
{
    // customised name "my_reservation_id" type
}
```

### Auto-Register Carbon datetime type mappings

[](#auto-register-carbon-datetime-type-mappings)

If the `nesbot/carbon` package is installed, this package will automatically register the Doctrine types provided by Carbon.

By default, it will overwrite the default Doctrine types for `datetime` and `datetime_immutable` with the Carbon equivalents:

```
datetime_immutable: \Carbon\Doctrine\DateTimeImmutableType
datetime: \Carbon\Doctrine\DateTimeType
```

If you wish the Carbon types to operate alongside the default DateTime and DateTimeImmutable types, set `replace:  false` in the bundle configuration. This will result in additional types being defined for the Carbon columns.

```
carbon_immutable: \Carbon\Doctrine\DateTimeImmutableType
carbon: \Carbon\Doctrine\DateTimeType
```

If you wish to completely disable this behaviour, set `enabled: false` in the bundle configuration.

```
headsnet_doctrine_tools:
  carbon_mappings:
    enabled: true
    replace: true
```

Contributions
-------------

[](#contributions)

Contributions are welcome via Pull Requests. Please include a single change in each PR.

License
-------

[](#license)

Released under the [MIT License](LICENSE).

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance74

Regular maintenance activity

Popularity30

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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

Every ~68 days

Recently: every ~89 days

Total

9

Last Release

178d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.1

v0.3.0PHP &gt;=8.2

### Community

Maintainers

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

---

Top Contributors

[![benr77](https://avatars.githubusercontent.com/u/2156742?v=4)](https://github.com/benr77 "benr77 (33 commits)")

---

Tags

phpsymfonyormdoctrine

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/headsnet-doctrine-tools-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/headsnet-doctrine-tools-bundle/health.svg)](https://phpackages.com/packages/headsnet-doctrine-tools-bundle)
```

###  Alternatives

[sonata-project/doctrine-orm-admin-bundle

Integrate Doctrine ORM into the SonataAdminBundle

46117.7M155](/packages/sonata-project-doctrine-orm-admin-bundle)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[fourlabs/qbjs-parser-bundle

This bundle is a Symfony wrapper for fourlabs/qbjs-parser.

1514.7k1](/packages/fourlabs-qbjs-parser-bundle)[vasek-purchart/doctrine-date-time-immutable-types-bundle

Bundle integration of Doctrine DateTimeImmutable types for Symfony

1085.6k](/packages/vasek-purchart-doctrine-date-time-immutable-types-bundle)

PHPackages © 2026

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