GitHub

php-datatypes-laravel-doctrine

php-datatypes-laravel-doctrine

Persist PHP Datatypes value objects with Doctrine DBAL - Laravel auto-wired, zero configuration

php-datatypes-laravel-doctrine

This package lets a hradigital/php-datatypes object be the declared type of a Doctrine Entity attribute. Doctrine persists only the types it ships with, so an EmailAddress, a Money or an Address would otherwise have to be declared as a primitive and converted by hand on every read and write. It ships one Doctrine DBAL Type per Datatypes object, plus a Laravel Service Provider that registers them all, so the Entity holds the Value Object while the database still holds a plain, indexable, human-readable value.

  • Doctrine DBAL Types - one per Datatypes object: StrType, EmailAddressType, UrlType, SlugType, DatetimeType, CurrencyType, MoneyType, AddressType and the rest.
  • Native PHP Types - NativeDateTimeType, NativeDateTimeImmutableType, NativeDateIntervalType and NativeDateTimeZoneType, so an Entity holding a plain \DateTime maps under the same naming convention.
  • Laravel Service Provider - auto-discovered, registering every Type before any EntityManager resolves a mapping. Nothing to publish, nothing to configure.
  • One naming rule - a Doctrine type name is always the Type class' own short name.
  • Validation on the way in - a Value Object's validation failure surfaces as a DBAL ConversionException, so an invalid value is rejected rather than corrupting the column.
  • Framework-optional - the Types are plain DBAL Types with no framework dependency; the Service Provider is a convenience.

What this package is not

  • Not a fork or a replacement for hradigital/php-datatypes. It depends on it and adds persistence, nothing more. The Value Objects' behaviour, validation and API are entirely theirs.
  • Not an ORM, and not a set of Entities. It contributes column types. Your Entities, mappings and repositories stay yours.
  • Not Laravel-only. See Using it outside Laravel.

Visit project