Download the PHP package hradigital/php-datatypes-laravel-doctrine without Composer

On this page you can find all versions of the php package hradigital/php-datatypes-laravel-doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-datatypes-laravel-doctrine

php-datatypes-laravel-doctrine

CI Release Latest Release Latest Version on Packagist Total Downloads PHP Version Laravel Last Commit Open Issues Contributors Stars Code Size Conventional Commits

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.

What this package is not

Requirements

Requirement Supported
PHP 8.2, 8.3, 8.4
hradigital/php-datatypes ^3.0
doctrine/dbal ^3.8, ^4.0
Laravel (illuminate/*) 12, 13

Laravel 13 itself requires PHP 8.3 or newer; on PHP 8.2 the package runs on Laravel 12.

Both DBAL majors are supported from one code base and both are exercised on every CI run.

A Doctrine ORM integration for Laravel - typically laravel-doctrine/orm - is what gives your application Entities in the first place. This package does not require it: it registers into Doctrine's own global Type registry, which every integration reads from.

Zero configuration

Install it and the Types are usable. There is nothing to publish, nothing to add to config/app.php, and nothing to add to your Doctrine config - Laravel's package auto-discovery finds the Service Provider, and the Service Provider registers every Type before any EntityManager resolves a mapping.

That is the whole installation. Skip straight to Usage.

At a glance

Nothing else changes. $user->getEmail() now hands you an EmailAddress, with its getUsername() / getDomain() / getTld() accessors and its validation, and the database still holds a plain, indexable, human-readable VARCHAR.

Usage

Declare the attribute with the Value Object's own type, and map the column with the matching Doctrine type name.

Attributes

Annotations

The naming rule

A Doctrine type name is always the Type class' own short name. An attribute declared as Money $total maps with type: 'MoneyType'; one declared as Slug $slug maps with type: 'SlugType'. There is no prefix to remember and no lookup table to consult - if you know the Value Object, you know the mapping.

The four Types covering native PHP classes carry a Native prefix, because three of them would otherwise collide with a Datatypes class: PHP's \DateInterval and \DateTimeZone share their short name with the Datatypes classes outright, and \DateTime differs from Datatypes' Datetime by a single capital letter. Without the prefix, a mapping would be one keystroke away from silently selecting the wrong Type.

Type reference

Datatypes library

Doctrine type PHP type on the Entity Column Notes
StrType HraDigital\Datatypes\Scalar\Str VARCHAR(255) Width overridable via length. Accepts a native string on write.
EmailAddressType …\Web\EmailAddress VARCHAR(255) Stores the case-normalized address, so equal addresses compare equal in SQL.
UrlType …\Web\Url VARCHAR(2048) Stores the normalized URL. See Indexing a URL.
SlugType …\Web\Seo\Slug VARCHAR(191) 191, not 255 - the widest utf8mb4 column InnoDB accepts in a single-column UNIQUE index.
DatetimeType …\Datetime\Datetime DATETIME
DatetimeTzType …\Datetime\Datetime DATETIME / TIMESTAMPTZ Only some platforms store the offset. See Timezones.
DateType …\Datetime\Datetime DATE Time resets to midnight on read.
TimeType …\Datetime\Datetime TIME Date resets to the epoch on read.
DateIntervalType …\Datetime\DateInterval VARCHAR(64) ISO-8601 duration, - prefixed when inverted.
DateTimeZoneType …\Datetime\DateTimeZone VARCHAR(64) IANA identifier, never a fixed offset.
CurrencyType …\Financial\Currency CHAR(3) ISO-4217 code. An unknown code fails rather than loading as null.
MoneyType …\Financial\Money JSON {"amount": <minor units, integer>, "currency": "<code>"}. See Multi-field Value Objects.
AddressType …\ValueObjects\Address JSON {"street", "postal_code", "city", "country"}. See Multi-field Value Objects.

Native PHP classes

Provided so an Entity holding a plain \DateTime maps with the same naming convention as one holding a Datatype. Behaviour matches Doctrine's own built-ins; these are a naming convenience, not a different conversion.

Doctrine type PHP type on the Entity Column Doctrine's own equivalent
NativeDateTimeType \DateTime DATETIME datetime
NativeDateTimeImmutableType \DateTimeImmutable DATETIME datetime_immutable
NativeDateIntervalType \DateInterval VARCHAR(64) dateinterval
NativeDateTimeZoneType \DateTimeZone VARCHAR(64) -

Null handling

Every Type passes null through untouched in both directions. A nullable attribute needs nothing beyond Doctrine's own nullable: true.

Invalid data

Every Type routes the Value Object's own validation failure into a Doctrine\DBAL\Types\ConversionException, so a malformed row surfaces as the DBAL error your application already handles - and an invalid value is rejected on the way in rather than corrupting the column. An unknown currency code, a relative URL, a slug with spaces and an unknown timezone identifier all fail loudly.

Datatypes deliberately without a Type

Not every object in the Datatypes library is a column. These have no Type, on purpose:

Object Why not
ValueObjects\Pagination A request-scoped query parameter, not entity state. It is never persisted.
Collections\* (Store, Queue, Stack, EntityCollection) Collections of entities or values. Doctrine models these as associations or as a json column of primitives - a Type would hide the relational structure.
Exceptions\* Control flow, not data.
Attributes\* traits, ValueObjects\Traits\* Traits that shape a class' behaviour; they have no value of their own to store.
ValueObjects\AbstractValueObject Abstract - the concrete Value Objects that extend it get their own mapping.

Multi-field Value Objects

Money and Address carry more than one field, so they have no single scalar form. This package maps each of them to one JSON column, which keeps the Value Object mappable as one Entity attribute - the whole point of the package.

That is not the only sensible mapping, and it is not always the right one. Both Value Objects are explicitly designed to be spread over one column per field:

Use the JSON Type when the Value Object is stored and read as a whole.

Use a Doctrine Embeddable over separate columns when the individual fields have to be queried, indexed, sorted or aggregated in SQL - summing order totals, filtering customers by city, putting a UNIQUE index on a postal code. A JSON column can do none of those efficiently on every platform.

Note that CurrencyType is useful on its own in exactly that split mapping.

Configuration (optional)

You do not need this. It exists for the two cases where the defaults do not fit: renaming a Type whose name clashes with another package's, and turning a Type off.

That writes config/datatypes-doctrine.php:

Rename a Type by changing its key; drop one by removing its entry.

A name already claimed by another package is never overwritten. The first registration wins and this package steps aside, because silently swapping another package's Type would corrupt its columns. Renaming here is the supported way to resolve a clash.

Platform notes

Timezones

DatetimeTzType stores the UTC offset only on platforms that have a timezone-aware column type - PostgreSQL TIMESTAMP WITH TIME ZONE, Oracle, SQL Server DATETIMEOFFSET. MySQL has no such column type, and DBAL falls back to a plain DATETIME, which silently drops the offset. On MySQL, prefer DatetimeType plus a separate timezone column mapped with DateTimeZoneType.

Indexing a URL

A URL routinely overflows what a database engine will index - InnoDB caps an index key at 3072 bytes, which a utf8mb4 VARCHAR(2048) blows straight past. When the column has to be unique, index Url::getHash() in a second, fixed-width column rather than widening the first one:

JSON columns across DBAL majors

The same MySQL platform renders a JSON column as LONGTEXT on DBAL 3 and as JSON on DBAL 4. Both are correct for their major; the stored document is identical either way.

Using it outside Laravel

The Types are plain Doctrine\DBAL\Types\Type subclasses with no framework dependency. Register them yourself:

DoctrineTypes::datatypes() and DoctrineTypes::natives() return the two halves separately, if you want only one of them.

Development

Every gate runs through the Makefile, so the command a developer runs locally is the command CI runs. make help lists them all.

Append QUIET=1 to any target for silent-on-success output. Scope the file-based gates with FILES="a.php b.php", and narrow a test run with FILTER=MoneyType.

Git hooks

Points git at the repo's version-controlled .githooks/:

Hooks are per-clone and opt-in, which is exactly why CI enforces the same rules independently.

Commit messages and releases

Releases are automatic and derived from the commit history. On a green CI run against master, the release workflow computes the next version and cuts a tag with generated notes.

Commit type Effect
BREAKING CHANGE: footer major
feat minor
everything else, including build, chore, ci, docs, fix, perf, refactor, revert, style, test patch

Every commit that lands on master ships a version - the version identifies the state of the project, so there is no "no release" bucket. A breaking change needs the footer, on its own line after a blank line; a feat!: suffix alone does not cut a major.

Licence

Released under the Mozilla Public License 2.0. See LICENSE.

MPL-2.0 is file-level copyleft: you may use, modify and distribute this package inside closed-source and commercial products, and you only have to publish your changes to this package's own files.

The licence covers the code. It grants no rights in the HRADigital names or logos - see TRADEMARK.md. Dependencies carry their own licences.

Copyright (c) HRADigital - Hugo Rafael Azevedo.


All versions of php-datatypes-laravel-doctrine with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-json Version *
doctrine/dbal Version ^3.8 || ^4.0
hradigital/php-datatypes Version ^3.2
illuminate/contracts Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hradigital/php-datatypes-laravel-doctrine contains the following files

Loading the files please wait ...