leongersen / entity-generator
Database-first Doctrine entity generator with oneToMany and manyToOne support
0.0.5
2020-01-24 09:54 UTC
Requires
- php: ^7.1
- greenlion/php-sql-parser: ^4.3
- nyholm/dsn: ^1.0
- symfony/console: ^4.0|^5.0
- symfony/filesystem: ^4.0|^5.0
- twig/twig: ^2.12|^3.0
Requires (Dev)
- symfony/var-dumper: ^4.0|^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The Doctrine Project will be removing support for generating entities in Doctrine 3.
Not all development workflows will fit the proposed entity-first database management strategy.
To keep supporting a database-first workflow this project implements an alternative database oriented entity generator.
Features
- Generate entities with type annotations, getters, setters, adders and removers;
- Supports
oneToManyandmanyToOnerelationships, including pluralization of properties and methods.
License
This project is licensed MIT and can be used for free in any personal or commercial project.
Usage
bin/entity-generator entity-generator:generate
Options
dsnAccepts the same format as Doctrine, so the value configured in.envcan be usednamespaceNamespace for the generated entities (DefaultApp\Entity)directoryOutput directory for the generated entities (Defaultsrc/Entity)collection-interfaceInterface name for the collection type to use in the generated entities (Default\Doctrine\Common\Collections\Collection)collection-implementation(Default\Doctrine\Common\Collections\ArrayCollection)
Using a DSN from a .env file
source .env bin/entity-generator entity-generator:generate --dsn $DATABASE_URL
Implementation
- A mapping is generated from an existing database using
SHOW CREATE TABLE. - Entity classes are rendered using a Twig template.
Limitations
- Only provides a
\PDObased driver and an mapper forMySQL-like sql dialects. - Annotations for (unique) indexes are not (yet) implemented
ManyToManyrelations are not (yet) supported (motivation)- Doctrine Custom types are not supported
Open issues
- Naming conflicts on
xyx_idwith a foreign key and fieldxyx(both becomexyz) - Naming conflicts on multiple foreign keys from one table to another (
xyz.abc_1_idandxyz.abc_2_idboth becomexyz.abcs) - Blobs are not yet implemented