doctrineum/boolean
最新稳定版本:2.2.0
Composer 安装命令:
composer require doctrineum/boolean
包简介
Enumeration type for Doctrine - booleans only
README 文档
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
统计信息
- 总下载量: 5.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-30