Skip to content

doctrineum/doctrineum-float

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doctrine Float enum

Build Status Test Coverage License

About

Adds Enum to Doctrine ORM (can be used as a @Column(type="float_enum")).

##Usage

<?php

use Doctrine\ORM\Mapping as ORM;
use Doctrineum\Float\FloatEnum;

/**
 * @ORM\Entity()
 */
class Person
{
    /**
     * @var int
     * @ORM\Id() @ORM\GeneratedValue(strategy="AUTO") @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var FloatEnum
     * @ORM\Column(type="float_enum")
     */
    private $height;
    
    public function __construct(FloatEnum $height)
    {
        $this->height = $height;
    }

    /**
     * @return FloatEnum
     */
    public function getHeight()
    {
        return $this->height;
    }
}

$tallMan = new Person(FloatEnum::getEnum(197.45));

/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager->persist($tallMan);
$entityManager->flush();
$entityManager->clear();

/** @var Person[] $persons */
$canSitOnFrontSeat = $entityManager->createQuery(
    "SELECT p FROM Person p WHERE p.height >= 140"
)->getResult();

var_dump($canSitOnFrontSeat[0]->getHeight()->getValue()); // 197.45;

##Installation

Add it to your list of Composer dependencies (or by manual edit your composer.json, the require section)

composer require jaroslavtyc/doctrineum-float

Doctrine integration

Register new DBAL type:

<?php

use Doctrineum\Float\FloatEnumType;

FloatEnumType::registerSelf();

When using Symfony with Doctrine you can do the same as above by configuration:

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        mapping_types:
            float_enum: float_enum
        types:
            float_enum: Doctrineum\Float\FloatEnumType

About

Enum with float value - for Doctrine

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages