Last active
January 4, 2023 09:23
-
-
Save JanMikes/1ceafba566b95536fd2d54442f417ae7 to your computer and use it in GitHub Desktop.
Example of simple and stupid value object
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
doctrine: | |
types: | |
- OdbavTo\Infrastructure\Persistence\Doctrine\Types\Person\FirstNameType |
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
Vygenerovat migrations, ktera smaze z commentu typu `(DC2Type:identity_uid)` |
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 OdbavTo\Domain\Model\Person; | |
use OdbavTo\Domain\Model\SimpleString; | |
class FirstName extends SimpleString | |
{ | |
} |
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 OdbavTo\Infrastructure\Persistence\Doctrine\Types\Person; | |
use OdbavTo\Domain\Model\Person\FirstName; | |
use OdbavTo\Infrastructure\Persistence\Doctrine\Types\StringType; | |
class FirstNameType extends StringType | |
{ | |
public function getPropertyClassName(): string | |
{ | |
return FirstName::class; | |
} | |
public function getName() | |
{ | |
return 'person_first_name'; | |
} | |
} |
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 OdbavTo\Domain\Model\Person; | |
use OdbavTo\Domain\Model\ValueObject; | |
use OdbavTo\Domain\Model\ValueObjectEquals; | |
use OdbavTo\Domain\Model\ValueObjectToString; | |
class Name implements ValueObject | |
{ | |
use ValueObjectToString; | |
use ValueObjectEquals; | |
/** @var FirstName */ | |
private $firstName; | |
/** @var LastName */ | |
private $lastName; | |
public function __construct(FirstName $firstName, LastName $lastName) | |
{ | |
$this->firstName = $firstName; | |
$this->lastName = $lastName; | |
} | |
public function value() | |
{ | |
return $this->firstName->value() . ' ' . $this->lastName->value(); | |
} | |
public function firstName(): FirstName | |
{ | |
return $this->firstName; | |
} | |
public function lastName(): LastName | |
{ | |
return $this->lastName; | |
} | |
public function isEmpty(): bool | |
{ | |
return $this->firstName->isNull() && $this->lastName->isNull(); | |
} | |
} |
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
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | |
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> | |
<embeddable name="OdbavTo\Domain\Model\Person\Name"> | |
<field name="firstName" type="person_first_name" nullable="true"/> | |
<field name="lastName" type="person_last_name" nullable="true"/> | |
</embeddable> | |
</doctrine-mapping> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment