doctrineum / float
Enumeration type for Doctrine - floats only
Installs: 5 887
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- doctrineum/scalar: ^3.1
- granam/float: ^5.0
- granam/float-enum: ^1.0
Requires (Dev)
- granam/exceptions-hierarchy: ~4.0
- mockery/mockery: ~1.0
- phpunit/phpunit: ~7.0
README
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