Created
April 27, 2017 12:01
-
-
Save szepczynski/d3028eb9f92fd7aadd08a578c7a92ad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SharedKernel\Domain\Model\Gender: | |
type: embeddable | |
fields: | |
value: { type: string, length: 8, column: gender, nullable: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace SharedKernel\Domain\Model; | |
use Assert\Assertion; | |
/** | |
* Class Gender | |
* @package SharedKernel\Domain\Model | |
*/ | |
class Gender implements \Tarifhaus\Doctrine\ORM\NullableEmbeddableInterface | |
{ | |
/** | |
* @var string | |
*/ | |
private $value; | |
/** | |
* @param string $gender | |
*/ | |
public function __construct(string $gender) | |
{ | |
$gender = strtolower($gender); | |
Assertion::inArray($gender, ['male', 'female']); | |
$this->value = $gender; | |
} | |
/** | |
* @return string | |
*/ | |
public function getValue(): string | |
{ | |
return $this->value; | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString(): string | |
{ | |
return $this->getValue(); | |
} | |
/** | |
* @return bool | |
*/ | |
public function isNull(): bool | |
{ | |
return $this->value === null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User\Domain\Model\User: | |
type: entity | |
table: users | |
id: | |
id: | |
type: userId | |
length: 36 | |
nullable: false | |
generator: | |
strategy: NONE | |
embedded: | |
gender: | |
class: SharedKernel\Domain\Model\Gender | |
columnPrefix: false |
Could you proof-read the README, I just added, are there any details missing? - https://github.com/tarifhaus/doctrine-nullable-embeddable/blob/master/README.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@szepczynski You would have to call
$listener->addMapping('User\Domain\Model\User', 'gender');
and the listener has to be registered withpostLoad
event of theUser\Domain\Model\User
entity.If you are using Symfony, the service definition would be something like:
I will add a README with an example to the repository :)