jungle-bay / doctrine-set-type
Set Type for Doctrine
Installs: 14 138
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Open Issues: 0
Requires
- php: >=5.5
- doctrine/dbal: ^2.5
Requires (Dev)
- phpunit/phpunit: ^4.8.36
This package is not auto-updated.
Last update: 2024-04-14 02:18:58 UTC
README
Set Type for Doctrine
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 NAME = 'roles_type'; const ROLE_SUPER_USER_VALUE = 'ROLE_SUPER_USER'; const ROLE_ADMIN_VALUE = 'ROLE_ADMIN'; const ROLE_USER_VALUE = 'ROLE_USER'; const ROLE_NONE_VALUE = 'ROLE_NONE'; protected function getValue() { return array( self::ROLE_SUPER_USER_VALUE, self::ROLE_ADMIN_VALUE, self::ROLE_USER_VALUE, self::ROLE_NONE_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 = "roles_type" * ) */ private $roles; }
Warning
Do not forget to register the type!
\Doctrine\DBAL\Types\TypeType::addType(RolesType::NAME, RolesType::class); /** @var \Doctrine\DBAL\Connection $conn */ $conn->getDatabasePlatform()->registerDoctrineTypeMapping('roles', RolesType::NAME);
License
This bundle is under the MIT license. See the complete license in the file: here.