dxi / doctrine-extension
DXI Doctrine Extensions
Installs: 1 828
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 6
Forks: 4
Open Issues: 2
Requires
- php: >=5.3.3
Requires (Dev)
- doctrine/dbal: ~2.3
- doctrine/mongodb-odm: ~1.0
- doctrine/orm: ~2.3
- gedmo/doctrine-extensions: ~2.3
- marc-mabe/php-enum: ~2.0
- mockery/mockery: *
- phpunit/phpunit: ~4@stable
Suggests
- doctrine/dbal: To support DBAL Type
- doctrine/mongodb-odm: To support MongoDB ODM Type
- gedmo/doctrine-extensions:: To support Reference Extension
- marc-mabe/php-enum: To support Enum Extension
This package is not auto-updated.
Last update: 2024-10-30 10:40:05 UTC
README
Doctrine 2 extensions
Installation
Add the dxi/doctrine-extension into composer.json
{ "require": { "php": ">=5.3.2", "dxi/doctrine-extension": "~1.0" } }
Enum Extension
This Extension provides convenient way to create Doctrine Mapping Types from your Enum Types. For now, only marc-mabe/php-enum is supported (see https://github.com/marc-mabe/php-enum).
- Create your Enum Type
class MyEnum extends \MabeEnum\Enum { const ONE = 'one'; const TWO = 'two'; }
- Define your Entity or Document
class MyEntity { private $id; /** * @var MyEnum */ private $myEnum; /** * @return MyEnum */ public function getMyEnum() { return $this->myEnum; } /** * @param MyEnum $myEnum */ public function setMyEnum(MyEnum $myEnum) { $this->myEnum = $myEnum; } public function getId() { return $this->id; } }
- Register your type with DBAL
use Dxi\DoctrineExtension\Enum\DBAL\DBALTypeRegistrar; use Dxi\DoctrineExtension\Enum\DBAL\DBALTypeClassGenerator; $targetDir = './enum-db-types'; $typeNamespace = 'My\Enum\DBALTypes'; $registrar = new DBALTypeRegistrar(new DBALTypeClassGenerator($targetDir, $typeNamespace)); $registrar->registerType('my_enum_type', '\MyEnum');
Now you can use my_enum_type with for Doctrine ORM mappings and with DBAL bindings. (see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html) Notice: Field mapped as my_enum_type creates column type "VARCHAR" (32 length by default, however you can use other "string" type properties)
- Register your type with MongoDB
use Dxi\DoctrineExtension\Enum\DBAL\DBALTypeRegistrar; use Dxi\DoctrineExtension\Enum\DBAL\DBALTypeClassGenerator; $targetDir = './enum-mongo-types'; $typeNamespace = 'My\Enum\MongoDbTypes'; $registrar = new MongoDbTypeRegistrar(new MongoDbTypeClassRegistrar($targetDir, $typeNamespace)); $registrar->registerType('my_enum_type', '\MyEnum');
Now you can use my_enum_type for your Doctrine MongoDB ODM mappings (see http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/basic-mapping.html#custom-mapping-types)
Reference Extension
It's a fork of the Gedmo/References extension. See https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/references.md It provides multi registry support and XML/YML mapping drivers. Note, this Extension will be removed, when it become part of Gedmo Doctrine Extension project (see doctrine-extensions/DoctrineExtensions#1320)