doctrineum / integer
Enumeration type for Doctrine - integers only
Installs: 6 103
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- doctrineum/scalar: ~4.0
- granam/integer-enum: ^1.0
Requires (Dev)
- granam/exceptions-hierarchy: ~4.0
- mockery/mockery: ~1.0
- phpunit/phpunit: ~7.0
- roave/security-advisories: dev-master
README
About
Adds Enum to Doctrine ORM
(can be used as a @Column(type="integer_enum")
).
##Usage
<?php use Doctrine\ORM\Mapping as ORM; use Doctrineum\Integer\IntegerEnum; /** * @ORM\Entity() */ class Journey { /** * @var int * @ORM\Id() @ORM\GeneratedValue(strategy="AUTO") @ORM\Column(type="integer") */ private $id; /** * @var IntegerEnum * @ORM\Column(type="integer_enum") */ private $distanceInKm; public function __construct(IntegerEnum $distanceInKm) { $this->distanceInKm = $distanceInKm; } /** * @return IntegerEnum */ public function getDistanceInKm() { return $this->distanceInKm; } } $toSun = new Journey(IntegerEnum::getEnum(152100000)); /** @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager->persist($toSun); $entityManager->flush(); $entityManager->clear(); /** @var Journey[] $StarTracks */ $StarTracks = $entityManager->createQuery( "SELECT j FROM Journey j WHERE j.distanceInKm >= 1000000" )->getResult(); var_dump($StarTracks[0]->getDistanceInKm()->getValue()); // 152100000;
##Installation
Add it to your list of Composer dependencies (or by manual edit your composer.json, the require
section)
composer require jaroslavtyc/doctrineum-integer
Doctrine integration
Register new DBAL type:
<?php use Doctrineum\Integer\IntegerEnumType; IntegerEnumType::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: integer_enum: integer_enum types: integer_enum: Doctrineum\Integer\IntegerEnumType