2017 © Pedro Peláez
 

library doctrine-intrange

Supports postgres intrange in Doctrine DBAL.

image

riccardonar/doctrine-intrange

Supports postgres intrange in Doctrine DBAL.

  • Thursday, January 26, 2017
  • by riccardonar
  • Repository
  • 1 Watchers
  • 1 Stars
  • 15,808 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 38 % Grown

The README.md

Doctrine IntRange Type

Thanks to @Salamek, this is an adapt to https://github.com/Salamek/doctrine-daterange, (*1)

Supports PostgreSQL DateRange in Doctrine DBAL., (*2)

Summary

The IntRange library, (*3)

  • adds a intrange type to DBAL

Installation

Add it to your list of Composer dependencies:, (*4)

composer require riccardonar/doctrine-intrange

Register it with Doctrine DBAL:, (*5)

<?php

use Doctrine\DBAL\Types\Type;
use riccardonar\Doctrine\DBAL\Types\IntRangeType;

Type::addType(
    IntRangeType::INTRANGE,
    'riccardonar\\Doctrine\\DBAL\\Types\\IntRangeType'
);

When using Symfony2 with Doctrine you can do the same as above by only changing your configuration:, (*6)

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        mapping_types:
            intrange: intrange
        types:
            intrange:  riccardonar\Doctrine\DBAL\Types\IntRangeType

Usage

<?php

/**
 * @Entity()
 * @Table(name="jobs")
 */
class Job
{
    /**
     * @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     * @Id()
     */
    private $id;

    /**
     * @Column(type="intrange")
     */
    private $range;

    /**
     * @return \riccardonar\IntRange
     */
    public function getRange()
    {
        return $this->range;
    }

    /**
     * @param \riccardonar\IntRange $range
     */
    public function setRange(array $range)
    {
        $this->range = $range;
    }
}

$annualJob = new Job();
$annualJob->setRange(new \riccardonar\IntRange(1, 6));

$entityManager->persist($annualJob);
$entityManager->flush();
$entityManager->clear();

$jobs = $entityManager->createQuery(
    "SELECT j FROM Jobs j"
)->getResult();

echo $jobs[0]->getRange()->getStartInt(); // 1
echo $jobs[0]->getRange()->getEndInt(); //  6

The Versions

26/01 2017

dev-master

9999999-dev https://github.com/riccardonar/doctrine-intrange

Supports postgres intrange in Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine range integer

26/01 2017

1.0.0

1.0.0.0 https://github.com/riccardonar/doctrine-intrange

Supports postgres intrange in Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine range integer