doctrineum / boolean
Enumeration type for Doctrine - booleans only
Installs: 5 716
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- doctrineum/scalar: ^3.1
- granam/boolean: ^3.1
- granam/boolean-enum: ^1.0
- granam/strict-object: ^3.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="boolean_enum")
).
##Usage
<?php use Doctrine\ORM\Mapping as ORM; use Doctrineum\Boolean\BooleanEnum; /** * @ORM\Entity() */ class Account { /** * @var int * @ORM\Id() @ORM\GeneratedValue(strategy="AUTO") @ORM\Column(type="integer") */ private $id; /** * @var BooleanEnum * @ORM\Column(type="boolean_enum") */ private $activated; public function __construct() { $this->activated = BooleanEnum::getEnum(false); } /** * @return BooleanEnum */ public function getActivated() { return $this->activated; } /** * @param BooleanEnum $activated */ public function setActivated(BooleanEnum $activated) { $this->activated = $activated; } } $account = new Account(); $account->setActivated(BooleanEnum::getEnum(true)); /** @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager->persist($account); $entityManager->flush(); $entityManager->clear(); /** @var Account[] $accounts */ $accounts = $entityManager->createQuery( "SELECT a FROM Account a WHERE a.activated" )->getResult(); var_dump($accounts[0]->getActivated()->getValue()); // true;
##Installation
Add it to your list of Composer dependencies (or by manual edit your composer.json, the require
section)
composer require jaroslavtyc/doctrineum-boolean
Note: NULL is prohibited. NULL means "I don't know" and that is not FALSE neither TRUE. If you want to use NULL, as lets say FALSE, do that conversion by your own, because you are the only one "who knows".
Doctrine integration
Register new DBAL type:
<?php use Doctrineum\Boolean\BooleanEnumType; BooleanEnumType::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: boolean_enum: boolean_enum types: boolean_enum: Doctrineum\Boolean\BooleanEnumType