jungle-bay / doctrine-enum-type

1.0 2017-12-12 10:02 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:10:19 UTC


README

Doctrine Logo

Doctrine 的枚举类型

Travis CI Scrutinizer CI Codecov

安装

推荐的安装方式是通过 Composer

composer require jungle-bay/doctrine-enum-type

使用示例

<?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;
    }
}
示例使用实体
<?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;
}

警告

不要忘记注册 类型

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

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

许可证

此捆绑包采用 MIT 许可证。请参阅完整的许可证,文件位于:[此处](https://github.com/jungle-bay/doctrine-enum-type/blob/master/license.txt)。