PHP code example of doctrineum / boolean
1. Go to this page and download the library: Download doctrineum/boolean library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
doctrineum / boolean example snippets
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;
use Doctrineum\Boolean\BooleanEnumType;
BooleanEnumType::registerSelf();