jungle-bay/doctrine-enum-type

Enum Type for Doctrine

1.0 2017-12-12 10:02 UTC

This package is not auto-updated.

Last update: 2024-05-12 00:53:28 UTC


README

Doctrine Logo

Enum Type for Doctrine

Travis CI Scrutinizer CI Codecov

Install

The recommended way to install is through Composer:

composer require jungle-bay/doctrine-enum-type

The simplest example of use

<?php

namespace Acme\Types;


use Doctrine\DBAL\Types\EnumType;

class SexType extends EnumType {

    const NAME = 'sex_type';

    const MAN_VALUE = 'MAN';
    const WOMAN_VALUE = 'WOMAN';


    protected function getValue() {
        return array(
            self::MAN_VALUE,
            self::WOMAN_VALUE
        );
    }


    public function getName() {
        return self::NAME;
    }
}
Example use entities
<?php

namespace Acme\Entities;


use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 * 
 * @ORM\Table(
 *     name = "users"
 * )
 */
class User {
    
    /**
     * @ORM\Column(
     *     type = "sex_type"
     * )
     */
    private $sex;
}

Warning

Do not forget to register the type!

\Doctrine\DBAL\Types\Type::addType(SexType::NAME, SexType::class);

/** @var \Doctrine\DBAL\Connection $conn */
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('sex', SexType::NAME);

License

This bundle is under the MIT license. See the complete license in the file: here.