/chronos-doctrine

Adds Doctrine DBAL Types for cakephp/chronos Immutable DateTime-Implementations

Primary LanguagePHPMIT LicenseMIT

chronos-doctrine

The warhuhn/chronos-doctrine library adds Doctrine DBAL Types that convert Date/DateTime-based database values to Immutable Chronos DateTime-Implementations.

Installation

composer.phar require warhuhn/chronos-doctrine

Configuration

doctrine/dbal in raw PHP

<?php

\Doctrine\DBAL\Types::addType('chronos_date', \Warhuhn\Doctrine\DBAL\Types\ChronosDateType::class);
\Doctrine\DBAL\Types::addType('chronos_datetime', \Warhuhn\Doctrine\DBAL\Types\ChronosDateTimeType::class);
\Doctrine\DBAL\Types::addType('chronos_datetimetz', \Warhuhn\Doctrine\DBAL\Types\ChronosDateTimeTzType::class);

Symfony

# app/config/config.yml
doctrine:
   dbal:
       types:
           chronos_date: Warhuhn\Doctrine\DBAL\Types\ChronosDateType
           chronos_datetime: Warhuhn\Doctrine\DBAL\Types\ChronosDateTimeType
           chronos_datetimetz: Warhuhn\Doctrine\DBAL\Types\ChronosDateTimeTzType

Usage in Doctrine ORM

<?php

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class Example
{
    /**
     * @var \Cake\Chronos\Date 
     * @ORM\Column(type="chronos_date")
     */
    private $date;
    
    /**
     * @var \Cake\Chronos\Chronos
     * @ORM\Column(type="chronos_datetime")
     */
    private $dateTime;
    
    /**
     * @var \Cake\Chronos\Chronos
     * @ORM\Column(type="chronos_datetimetz")
     */
    private $dateTimeTz;
}