2017 © Pedro PelĂĄez
 

library boolean

Enumeration type for Doctrine - booleans only

image

doctrineum/boolean

Enumeration type for Doctrine - booleans only

  • Wednesday, July 18, 2018
  • by jaroslavtyc
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5,671 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

Doctrine Boolean enum

Build Status Test Coverage License, (*1)

About

Adds Enum to Doctrine ORM (can be used as a @Column(type="boolean_enum"))., (*2)

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), (*3)

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"., (*4)

Doctrine integration

Register new DBAL type:, (*5)

<?php

use Doctrineum\Boolean\BooleanEnumType;

BooleanEnumType::registerSelf();

When using Symfony with Doctrine you can do the same as above by configuration:, (*6)

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        mapping_types:
            boolean_enum: boolean_enum
        types:
            boolean_enum: Doctrineum\Boolean\BooleanEnumType

The Versions

18/07 2018
19/02 2017

2.0.x-dev

2.0.9999999.9999999-dev

Enumeration type for Doctrine - booleans only

  Sources   Download

MIT

The Requires

 

The Development Requires

19/02 2017
19/02 2017
28/12 2016

1.0.x-dev

1.0.9999999.9999999-dev

Enumeration type for Doctrine - bools only

  Sources   Download

MIT

The Requires

 

The Development Requires

28/12 2016

1.0.1

1.0.1.0

Enumeration type for Doctrine - bools only

  Sources   Download

MIT

The Requires

 

The Development Requires

02/11 2015

1.0.0

1.0.0.0

Enumeration type for Doctrine - bools only

  Sources   Download

MIT

The Requires

 

The Development Requires