eelan / doctrine-traits
A collection of traits for Doctrine entities.
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/eelan/doctrine-traits
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โphoneEmailTraitโemail
Eelan\DoctrineTraits\Personal
NameTraitโfirstName,lastNameGenderTraitโgender(based on enumGender:MALE,FEMALE,OTHER,UNKNOWN)BirthTraitโbirthDate,birthPlace
Eelan\DoctrineTraits\Location
AddressTraitโstreetName,streetNumber,postalCode,cityExtendedAddressTraitโ extendsAddressTraitand addsregion,countryGpsCoordinateTraitโ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.