Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Jeckel-Lab/advanced-types

Repository files navigation

CircleCI Latest Stable Version Total Downloads Build Status codecov Dependabot Status

Advanced PHP Types

Installation

composer require jeckel-lab/advanced-types

Types

Enum

See documentation of marc-mabe/php-enum.

The only addition is the implementation of JsonSerializable interface to serialize enum as it's value.

Value Object

  • Color
  • DateTimePeriod
  • Email
  • TimeDuration
  • Url

Usage with doctrine

Configure type DBAL:

# config/packages/doctrine.yaml

doctrine:
    dbal:
        types:
            color: JeckelLab\AdvancedTypes\DBAL\Types\ColorType
            email: JeckelLab\AdvancedTypes\DBAL\Types\EmailType
            time_duration: JeckelLab\AdvancedTypes\DBAL\Type\sTimeDurationType
            url: JeckelLab\AdvancedTypes\DBAL\Types\UrlType

Use it in your entity:

<?php

use Doctrine\ORM\Mapping as ORM;
use JeckelLab\Types\ValueObject\TimeDuration;

/**
 * @ORM\Entity(repositoryClass="App\Repository\TimeEntryRepository")
 */
class TimeEntry
{
    // ...

    /**
     * @ORM\Column(type="time_duration", nullable=true)
     * @var TimeDuration|null
     */
    private $duration;

    // ...
}