riccardonar / doctrine-intrange
Supports postgres intrange in Doctrine DBAL.
Installs: 160 469
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: >=5.3.3
- doctrine/dbal: ~2.2,>=2.2.3
- riccardonar/php-intrange: *
Requires (Dev)
- doctrine/orm: ~2.2,>=2.2.3
- phpunit/phpunit: 3.7.*
This package is auto-updated.
Last update: 2024-12-23 20:44:13 UTC
README
Thanks to @Salamek, this is an adapt to https://github.com/Salamek/doctrine-daterange
Supports PostgreSQL DateRange in Doctrine DBAL.
Summary
The IntRange
library
- adds a
intrange
type to DBAL
Installation
Add it to your list of Composer dependencies:
composer require riccardonar/doctrine-intrange
Register it with Doctrine DBAL:
<?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:
# 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