doctrineum / string
String-only enumeration type and value dependent sub-type for Doctrine
Installs: 1 632
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- doctrineum/scalar: ^3.1
- granam/string: ^3.0
- granam/string-enum: ^1.0
Requires (Dev)
- granam/exceptions-hierarchy: ~4.0
- mockery/mockery: ~1.0
- phpunit/phpunit: ~7.0
README
About
Adds Enum to Doctrine ORM
(can be used as a @Column(type="string_enum")
).
##Usage
<?php use Doctrine\ORM\Mapping as ORM; use Doctrineum\String\StringEnum; /** * @ORM\Enity() */ class Person { /** * @var int * @ORM\Id() @ORM\GeneratedValue(strategy="AUTO") @ORM\Column(type="integer") */ private $id; /** * @var StringEnum * @ORM\Column(type="string_enum") */ private $name; public function __construct(StringEnum $name) { $this->name = $name; } /** * @return StringEnum */ public function getName() { return $this->name; } } // ... entity Money using Currency $trueHero = new Person(StringEnum::getEnum('Don Quixote de La Mancha')); /** @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager->persist($trueHero); $entityManager->flush(); $entityManager->clear(); /** @var Currency[] $StarTracks */ $sirs = $entityManager->createQuery( "SELECT p FROM Person p WHERE p.name LIKE 'Don %'" )->getResult(); var_dump($sirs[0]->getName()->getValue()); // 'Don Quixote de La Mancha';
##Installation
Add it to your list of Composer dependencies (or by manual edit your composer.json, the require
section)
composer require jaroslavtyc/doctrineum-string
Doctrine integration
Register new DBAL type:
<?php use Doctrineum\String\StringEnumType; StringEnumType::registerSelf();
When using Symfony with Doctrine you can do the same as above by configuration:
# app/config/config.yml # Doctrine Configuration doctrine: dbal: # ... mapping_types: string_enum: string_enum types: string_enum: Doctrineum\String\StringEnumType