eelan / doctrine-traits
A collection of traits for Doctrine entities.
0.0.2
2025-04-13 17:17 UTC
Requires
- doctrine/orm: ^2.16 || ^3.0
README
Reusable PHP traits for Doctrine entities, designed for Symfony projects.
This library provides a collection of common traits to reduce boilerplate code when working with Doctrine ORM.
๐ฆ Installation
Install via Composer:
composer require eelan/doctrine-traits
โ ๏ธ If the package is not yet published on Packagist, you can include the GitHub repository manually in your
composer.json
.
๐งฑ Available Traits
Eelan\DoctrineTraits\Common
IdTrait
โ Auto-increment integer IDTimestampTrait
โcreatedAt
,updatedAt
(with lifecycle callbacks)SoftDeleteTrait
โdeletedAt
, withdelete()
andrestore()
methods
Eelan\DoctrineTraits\Contact
PhoneTrait
โphone
EmailTrait
โemail
Eelan\DoctrineTraits\Personal
NameTrait
โfirstName
,lastName
GenderTrait
โgender
(based on enumGender
:MALE
,FEMALE
,OTHER
,UNKNOWN
)BirthTrait
โbirthDate
,birthPlace
Eelan\DoctrineTraits\Location
AddressTrait
โstreetName
,streetNumber
,postalCode
,city
ExtendedAddressTrait
โ extendsAddressTrait
and addsregion
,country
GpsCoordinateTrait
โlatitude
,longitude
, and grouped coordinate helpers
๐ Usage
In your Doctrine entity:
use Eelan\DoctrineTraits\Common\IdTrait; use Eelan\DoctrineTraits\Location\AddressTrait; use Eelan\DoctrineTraits\Contact\EmailTrait; class Person { use IdTrait; use AddressTrait; use EmailTrait; // your custom fields... }
All fields are mapped using PHP 8+ attributes (#[ORM\Column(...)]
).
๐งช Example Entity
See examples/Person.php for a complete example using all traits.
๐ License
This project is licensed under the MIT License.
See the LICENSE file for details.
๐ Contributions
Contributions are welcome!
Feel free to open an issue or submit a pull request with new traits or improvements.