PHPackages                             dodo-it/entity-generator - 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. dodo-it/entity-generator

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

dodo-it/entity-generator
========================

Entity generator from database for almost any DBAL

2.1.1(1y ago)6127.8k—0%11MITPHPPHP ^8.1

Since Feb 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dodo-it/entity-generator)[ Packagist](https://packagist.org/packages/dodo-it/entity-generator)[ RSS](/packages/dodo-it-entity-generator/feed)WikiDiscussions master Synced 1mo ago

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

Entity generator
----------------

[](#entity-generator)

Highly customizable (typed) entity generator from database. It can generate entities for whole database, table/view and from raw SQL query

---

[![Latest Stable Version](https://camo.githubusercontent.com/696707a81ce1dcb714b88ef28038dbbc0e809be9b11426efb16c50d1e2433c33/68747470733a2f2f706f7365722e707567782e6f72672f646f646f2d69742f656e746974792d67656e657261746f722f762f737461626c65)](https://packagist.org/packages/dodo-it/entity-generator)[![build](https://github.com/dodo-it/entity-generator/workflows/build/badge.svg)](https://github.com/dodo-it/entity-generator/actions?query=workflow%3Abuild)[![Coverage Status](https://camo.githubusercontent.com/3c873a9be1dc7ad252bdf9ae8ef3ba5b9393003640eb87b312aeb6caecb26f64/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f646f646f2d69742f656e746974792d67656e657261746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/dodo-it/entity-generator?branch=master)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)[![Total Downloads](https://camo.githubusercontent.com/3dd7b3793bad60848369c35b16b6f5116a003b0699679143c5a7a77f2b0124b3/68747470733a2f2f706f7365722e707567782e6f72672f646f646f2d69742f656e746974792d67656e657261746f722f646f776e6c6f616473)](https://packagist.org/packages/dodo-it/entity-generator)[![License](https://camo.githubusercontent.com/75ea6861dbcdf4ef3dc3cad2ff8d99b9ce4607f654a27cae44e1d1e1cd6c8a92/68747470733a2f2f706f7365722e707567782e6f72672f646f646f2d69742f656e746974792d67656e657261746f722f6c6963656e7365)](https://packagist.org/packages/dodo-it/entity-generator)

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

[](#installation)

```
$ composer require dodo-it/entity-generator

```

How to run:
-----------

[](#how-to-run)

```
   $config = new \DodoIt\EntityGenerator\Generator\Config([
       'path' =>  __DIR__ . '/Entities',
       'extends' => \Examples\Pdo\Entities\Entity::class,
       'namespace' => 'Examples\Pdo\Entities'
   ]);

   $pdo = new \PDO('mysql:dbname=example;host=127.0.0.1', 'root', '');

   $generatorFactory = new \DodoIt\EntityGenerator\Factory\GeneratorPdoFactory($pdo);
   $generator = $generatorFactory->create($config);
   $generator->generate();
```

What kind of entities can I get?
--------------------------------

[](#what-kind-of-entities-can-i-get)

Tool is highly customizable and can generate various different entity types of which most interesting are:

- PHP 7.4 typed properties

```
class ArticleEntity extends YourBaseEntity
{
   public int $id;

   public ?string $title;

   public bool $published;

   public ?\DateTimeInterface $created_at;
}
```

- properties with phpdoc

```
class ArticleEntity extends YourBaseEntity
{

	/** @var int */
	protected $id;

	/** @var string */
	protected $title;

	/** @var bool */
	protected $published;

	/** @var \DateTimeInterface */
	protected $created_at;
}
```

- properties with getters and setters (methods body is customizable)

```
class ArticleEntity extends YourBaseEntity
{

	public function getId(): int
	{
		return $this->id;
	}

	public function setId(int $value): self
	{
		$this['id'] = $value;
		return $this;
	}

	public function getTitle(): ?string
	{
		return $this->title;
	}

	public function setTitle(?string $value): self
	{
		$this['title'] = $value;
		return $this;
	}

	public function getPublished(): bool
	{
		return $this->published;
	}

	public function setPublished(bool $value): self
	{
		$this['published'] = $value;
		return $this;
	}

	public function getCreatedAt(): ?\DateTimeInterface
	{
		return $this->created_at;
	}

	public function setCreatedAt(?\DateTimeInterface $value): self
	{
		$this['created_at'] = $value;
		return $this;
	}
```

- phpdoc properties

```
/**
 * @property int $id
 * @property string $title
 * @property int $published
 * @property \DateTimeInterface $created_at
 */
class ArticleEntity extends YourBaseEntity
{
}
```

- properties with phpdoc

```
class ArticleEntity extends YourBaseEntity
{
	/** @var int */
	public $id;

	/** @var string */
	public $title;

	/** @var bool */
	public $published;

	/** @var \DateTimeInterface */
	public $created_at;
```

- it can generate column constants (use generateColumnConstants option)

```
class ArticleEntity extends YourBaseEntity
{
    	public const TABLE_NAME = 'articles';
    	public const ID = 'id';
    	public const TITLE = 'title';
    	public const PUBLISHED = 'published';
    	public const CREATED_AT = 'created_at';

.
.
.
```

- almost any combination you can imagine, check src/Generator/Config.php for list of all options see example folder

You can add your own methods to entities and change getter/setter functions, they won't be overriden when regenerated if rewrite flag is set to false

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

[](#configuration)

see src/Generator/Config.php

Docker integration
==================

[](#docker-integration)

Entity Generator image
----------------------

[](#entity-generator-image)

[![Docker Pulls](https://camo.githubusercontent.com/5f1b6449e5e72f29d1fe6649e0d3ca7bda0624635b8c6232dbffaf632879781d/68747470733a2f2f696d672e736869656c64732e696f2f646f636b65722f70756c6c732f7069666f7532352f656e746974792d67656e657261746f72)](https://camo.githubusercontent.com/5f1b6449e5e72f29d1fe6649e0d3ca7bda0624635b8c6232dbffaf632879781d/68747470733a2f2f696d672e736869656c64732e696f2f646f636b65722f70756c6c732f7069666f7532352f656e746974792d67656e657261746f72)

Generation from existing database
---------------------------------

[](#generation-from-existing-database)

The database should be accessible from the docker network, the hostname is either the name of the Mysql running container, or `localhost` if db is running on host. The below command will generate entities into `./entities` directory.

```
docker run --rm -v $PWD/entities:/app/entities --network some-network \
   -e MYSQL_HOSTNAME=some-mariadb \
   -e MYSQL_DATABASE=exmple-database \
   -e MYSQL_USERNAME=example-user \
   -e MYSQL_PASSWORD=my_cool_secret \
    pifou25/entity-generator

```

namespace and extends example
-----------------------------

[](#namespace-and-extends-example)

The base class must exist into /entities to be declared

```
docker run --rm -v $PWD/include/entities:/app/entities --network scripts_default \
   -e MYSQL_HOSTNAME=myhost \
   -e MYSQL_DATABASE=mydb \
   -e MYSQL_USERNAME=myuser \
   -e MYSQL_PASSWORD=mypwd \
   -e ENTITY_NAMESPACE=Example\\Pdo\\Entities \
   -e BASECLASS=Example\\Pdo\\Entities\Entity \
    entity-generator

```

Generation from flat plain SQL file
-----------------------------------

[](#generation-from-flat-plain-sql-file)

The `docker compose` file create a new database and initialize it with SQL data, you have to put SQL init file into `./examples` directory. When db is ready, the entity-generator start on it to generate PHP entities.

It is as simple as running this command from the `docker` directory : `docker compose up`

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance43

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 98.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 ~109 days

Recently: every ~272 days

Total

21

Last Release

456d ago

Major Versions

1.2.1 → 2.0.02022-07-14

PHP version history (4 changes)1.0.0PHP ^7.1

1.1.1PHP ^7.1|^8.0

1.2.0PHP ^8.0

2.1.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![dakorpar](https://avatars.githubusercontent.com/u/9303856?v=4)](https://github.com/dakorpar "dakorpar (83 commits)")[![pifou25](https://avatars.githubusercontent.com/u/20190031?v=4)](https://github.com/pifou25 "pifou25 (1 commits)")

---

Tags

databaseentitiesgeneratorphp74nettedatabasegeneratormysqlpdoentitytable

###  Code Quality

TestsPHPUnit

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dodo-it-entity-generator/health.svg)

```
[![Health](https://phpackages.com/badges/dodo-it-entity-generator/health.svg)](https://phpackages.com/packages/dodo-it-entity-generator)
```

###  Alternatives

[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5656.7M234](/packages/nette-database)[liqueurdetoile/cakephp-orm-json

Cakephp plugin to provide easy control over JSON type fields in database

1461.1k](/packages/liqueurdetoile-cakephp-orm-json)[sorskod/db

PDO wrapper. Extends PDO and PDOStatement with useful methods.

788.1k2](/packages/sorskod-db)

PHPackages © 2026

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