Doctrine Support

Doctrine Support#

Packagist GitLab GitHub Codeberg Gitea

Doctrine support is split into a separate package.

Installation#

composer require 'arokettu/date-doctrine'

Available Types#

  • DateType. Date stored in a native DATE column.

  • DateIntType. Date stored in an integer column as a Julian day value.

Usage#

Register types:

<?php

use Arokettu\Date\Doctrine\DateIntType;
use Arokettu\Date\Doctrine\DateType;
use Doctrine\DBAL\Types\Type;

// registers types directly
Type::addType(DateType::NAME, DateType::class);
Type::addType(DateIntType::NAME, DateIntType::class);

Note

See your framework documentation for proper configuration of custom Doctrine types.

Apply type to a model:

<?php

use Arokettu\Date\Date;
use Arokettu\Date\Doctrine\DateIntType;
use Arokettu\Date\Doctrine\DateType;
use Doctrine\ORM\Mapping\{Column, Entity, Table};

#[Entity, Table(name: 'date_object')]
class DateObject
{
    #[Column(type: DateType::NAME)]
    public Date $date;

    #[Column(type: DateIntType::NAME)]
    public Date $dateInt;
}