PHPackages                             ecommit/doctrine-entities-generator-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. ecommit/doctrine-entities-generator-bundle

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

ecommit/doctrine-entities-generator-bundle
==========================================

Generate Doctrine ORM entities.

v3.1.0(2mo ago)26.7k↑11.1%1MITPHPPHP ^8.1CI passing

Since Feb 2Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/e-commit/doctrine-entities-generator-bundle)[ Packagist](https://packagist.org/packages/ecommit/doctrine-entities-generator-bundle)[ RSS](/packages/ecommit-doctrine-entities-generator-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (24)Versions (19)Used By (0)

EcommitDoctrineEntitiesGeneratorBundle
======================================

[](#ecommitdoctrineentitiesgeneratorbundle)

The EcommitDoctrineEntitiesGeneratorBundle bundle (for Symfony) allows the user to (re)generate getters-setters methods for Doctrine ORM entities.

[![Tests](https://github.com/e-commit/doctrine-entities-generator-bundle/workflows/Tests/badge.svg)](https://github.com/e-commit/doctrine-entities-generator-bundle/workflows/Tests/badge.svg)

Bundle versionCompatible with Doctrine ORM3.\*, 4.\*≥ 3.2 ; &lt; 4.02.\*≥ 2.7 ; &lt; 3.0Installation
------------

[](#installation)

Install the bundle with Composer : In your project directory, execute the following command :

```
$ composer require ecommit/doctrine-entities-generator-bundle
```

Enable the bundle in the `config/bundles.php` file for your project :

```
return [
    //...
    Ecommit\DoctrineEntitiesGeneratorBundle\EcommitDoctrineEntitiesGeneratorBundle::class => ['dev' => true],
    //...
];
```

Usage
-----

[](#usage)

Add the start tag to your entity :

```
    /*
     * Getters / Setters (auto-generated)
     */
```

**WARNING** : The content between this start tag and the end of the PHP class will be deleted when the bundle generates the getters-setters methods. The getters-setters methods will be generated between these two tags.

For example:

```
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected int $categoryId;

    #[ORM\Column(type: 'string', length: 255)]
    protected string $name;

    /*
     * Getters / Setters (auto-generated)
     */

    //Content after this block will be deleted when
    //the bundle generates the getters-setters methods.
    //Getters-setters methods will be generated here.
}
```

You can change the start tag and the end tag (the end of the PHP class by default) : See the "FAQ" section.

In your project directory, execute the following command :

```
$ php bin/console ecommit:doctrine:generate-entities {Classename}
```

For example:

```
$ php bin/console ecommit:doctrine:generate-entities App/Entity/MyEntity
```

Each slash is replaced by an anti-slash.

You can use the `*` joker (which generates multiple entities). For example:

```
$ php bin/console ecommit:doctrine:generate-entities App/Entity/*
```

The bundle generates getters-setters methods for an entity only if :

- The PHP class is a Doctrine ORM entity; and
- The entity is not an interface; and
- The entity is not a trait; and
- The entity doesn't use the `Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\IgnoreGenerateEntity` attribute.

The bundle generates getters-setters methods for an entity property only if :

- The property is defined directly in the entity (and is not defined in an inherited class or a trait); and
- The property is not public; and
- The methods (getters-setters) do not exist (except if the method is defined between the start and end tags).

Getter-setter generation prioritizes PHP property type hints over Doctrine types. If a property has a PHP type hint, it will be used for the generated getters-setters. If no PHP type hint is declared, the getter-setter type will be inferred from the Doctrine type. This behavior can be changed by customizing the template (see the FAQ).

Getter-setter generation follows PHP nullability: when a PHP property type hint is present, generated types are nullable only if the property type hint is nullable. When the PHP type hint is missing, generated types default to nullable. This behavior can be changed by customizing the template (see the FAQ).

If a property has a PHPDoc `@var` annotation, it will also be included in the generated getter-setter (except for `addXXX` and `removeXXX` methods on to-many relationships). This behavior can be changed by customizing the template (see the FAQ).

FAQ
---

[](#faq)

### How can I change the generated code ?

[](#how-can-i-change-the-generated-code-)

When the code is generated, the `@EcommitDoctrineEntitiesGenerator/Theme/base.php.twig` Twig template is used.

You can create a custom template (that extends the base template).

**Solution 1 - Override the bundle**

See

**Solution 2 - Configure the template**

In your project configuration, you can configure the theme used by the bundle. For example, you can create the `config/packages/dev/ecommit_doctrine_entities_generator.yaml` file:

```
ecommit_doctrine_entities_generator:
    template: "your_template.php.twig"
```

**Solution 3 - Create a custom template in entity**

You can override the theme to be used by the bundle only for an entity. To do this, use the `Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\GenerateEntityTemplate` attribute:

```
use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\GenerateEntityTemplate;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
#[GenerateEntityTemplate("your_template.php.twig")]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected int $categoryId;
    //...
}
```

### How can I change the start-end tags ?

[](#how-can-i-change-the-start-end-tags-)

You can change the template (see previous question).

The start tag is defined in the `start_tag` Twig block.

The end tag is defined in the `end_tag` Twig block.

For example, you can create this theme:

```
{% extends '@EcommitDoctrineEntitiesGenerator/Theme/base.php.twig' %}

{% block end_tag %}

    /*
     * End Getters / Setters (auto-generated)
     */
{% endblock %}
```

and use as follows:

```
use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\GenerateEntityTemplate;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
#[GenerateEntityTemplate('your_template.php.twig')]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected int $categoryId;
    //...

    /*
     * Getters / Setters (auto-generated)
     */

    /*
     * End Getters / Setters (auto-generated)
     */
}
```

### How can I create a constructor in my entity ?

[](#how-can-i-create-a-constructor-in-my-entity-)

If your entity has a `TOMANY` association, the bundle will create a constructor in your entity. For this reason, manually defining a constructor in your entity is not allowed.

Instead, you can use the `Ecommit\DoctrineEntitiesGeneratorBundle\Entity\EntityInitializerInterface` interface and its `initializeEntity` method.

```
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Entity\EntityInitializerInterface;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
class Category implements EntityInitializerInterface
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected int $categoryId;

    #[ORM\OneToMany(targetEntity: 'Ecommit\DoctrineEntitiesGeneratorBundle\Tests\App\Entity\Book', mappedBy: 'category')]
    protected Collection $books;

    #[ORM\Column(type: 'datetime')]
    protected \DateTime $createdAt;

    public function initializeEntity(): void
    {
        $this->createdAt = new \DateTime('now');
    }

    //...
}
```

The `initializeEntity` method will be automatically called in the constructor generated in this way.

### An EntityInitializerInterfaceNotUsedException exception is thrown

[](#an-entityinitializerinterfacenotusedexception-exception-is-thrown)

An `Ecommit\DoctrineEntitiesGeneratorBundle\Exception\EntityInitializerInterfaceNotUsedException`exception is thrown if you define manually a constructor in your entity when a `TOMANY` association is used.

See the previous question.

### A TagNotFoundException exception is thrown

[](#a-tagnotfoundexception-exception-is-thrown)

The start and/or end tag was not found in your entity.

### How can I ignore the generation of getters-setters methods for an entity ?

[](#how-can-i-ignore-the-generation-of-getters-setters-methods-for-an-entity-)

Not all entities are processed (see the "Usage" section to find out which classes can be generated).

You can ignore the generation of getters-setters methods for an entity by using the `Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\IgnoreGenerateEntity` attribute :

```
use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\IgnoreGenerateEntity;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
#[IgnoreGenerateEntity]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected int $categoryId;
    //...
}
```

### How can I ignore the generation of getters-setters methods for a property ?

[](#how-can-i-ignore-the-generation-of-getters-setters-methods-for-a-property-)

Not all properties are processed (see the "Usage" section to find out which properties can be generated).

### Why was no method generated ?

[](#why-was-no-method-generated-)

See the last two questions.

Limitations
-----------

[](#limitations)

The bundle only works under the following conditions :

- The Doctrine attributes are used (Doctrine annotations are not compatible).
- Only one entity (PHP class) per PHP file
- The getters and setters of an embeddable are generated only if it's embedded at least once in an entity
- Inside each entity (PHP class) :
    - Only one property per line
    - Only one method per line (but a method can be defined through over lines)
- EOL (End Of Line) = LF

License
-------

[](#license)

This bundle is available under the MIT license. See the complete license in the *LICENSE* file.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance84

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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 ~108 days

Recently: every ~1 days

Total

18

Last Release

83d ago

Major Versions

v2.0.0 → v3.0.0-BETA12024-11-21

v2.1.0 → v3.0.02024-12-14

v2.1.1 → v3.0.12024-12-30

v2.3.0 → 3.x-dev2026-02-13

v3.1.0 → v4.0.0-BETA12026-02-16

PHP version history (5 changes)v0.1.0PHP ^7.2|^8.0

v1.1.0PHP ^7.4|^8.0

v2.0.0PHP ^8.0

v3.0.0-BETA1PHP ^8.1

v4.0.0-BETA1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/73191162d97fffaa1a23d23326a7a77fbaa94ce41e49cf4ee6cbf0b9c9800c80?d=identicon)[e-commit](/maintainers/e-commit)

---

Top Contributors

[![hlecorche](https://avatars.githubusercontent.com/u/188749?v=4)](https://github.com/hlecorche "hlecorche (151 commits)")

---

Tags

doctrinedoctrine-orm-entitiesentitygettersphpsetterssymfonygeneratordoctrineentitygettersetterSymfony Bundle

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ecommit-doctrine-entities-generator-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M650](/packages/sylius-sylius)[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.3k](/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)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

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

PHPackages © 2026

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