jungle-bay/doctrine-set-type

Set Type for Doctrine


Keywords
php, doctrine, doctrine-type, doctrine-type-set, set, type
License
MIT

Documentation

Set Type for Doctrine

Travis CI Scrutinizer CI Codecov SensioLabsInsight

Install

The recommended way to install is through Composer:

composer require jungle-bay/doctrine-set-type

The simplest example of use

<?php

namespace Acme\Types;


use Doctrine\DBAL\Types\SetType;

class RolesType extends SetType {

    const ROLE_SUPER_USER = 'ROLE_SUPER_USER';
    const ROLE_ADMIN = 'ROLE_ADMIN';

    const ROLE_USER = 'ROLE_USER';

    const ROLE_NONE = 'ROLE_NONE';


    protected function getValue() {
        return array(
            self::ROLE_SUPER_USER,
            self::ROLE_ADMIN,
            self::ROLE_USER,
            self::ROLE_NONE
        );
    }


    public function getName() {
        return 'roles_type';
    }
}
Example use entities
<?php

use Doctrine\ORM\Mapping as ORM;

class User {
    
    /**
     * @ORM\Column(
     *     type = "roles_type"
     * )
     */
    private $roles;
}

Warning

Do not forget to register the type!

use Doctrine\DBAL\Types\Type;

Type::addType('roles_type', RolesType::class);

$conn->getDatabasePlatform()->registerDoctrineTypeMapping('roles', 'roles_type');

License

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