Last active
November 2, 2015 10:38
-
-
Save dadamssg/c4cea613cfdbb448d586 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
namespace Acme\Project\Model\User\ValueObject; | |
class UserId | |
{ | |
/** | |
* @var string | |
*/ | |
private $id; | |
/** | |
* @param string $id | |
*/ | |
public function __construct($id) | |
{ | |
Assert::guid($id, "Invalid user id."); | |
$this->id = $id; | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return $this->id; | |
} | |
} |
This file contains hidden or 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 | |
namespace Acme\Project\Model\User\ValueObject; | |
class Username | |
{ | |
/** | |
* @var string | |
*/ | |
private $value; | |
/** | |
* @param string $id | |
*/ | |
public function __construct($value) | |
{ | |
Assert::string($value, "Invalid username."); | |
Assert::betweenLength($value, 3, 21, "Username must be between 4 and 20 characters in length."); | |
$this->value = $value; | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return $this->value; | |
} | |
} |
This file contains hidden or 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 | |
namespace Acme\Project\Model\User\Entity; | |
class User | |
{ | |
/** | |
* @var string | |
*/ | |
private $id; | |
/** | |
* @var Username | |
*/ | |
private $username; | |
/** | |
* @param UserId $id | |
* @param Username $username | |
*/ | |
public function __construct(UserId $id, Username $username) | |
{ | |
$this->id = (string)$id; | |
$this->username = $username; | |
} | |
/** | |
* @return UserId | |
*/ | |
public function getId() | |
{ | |
return new UserId($this->id); | |
} | |
} |
This file contains hidden or 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
Acme\Project\Model\User\Entity\User: | |
type: Entity | |
id: | |
id: | |
type: guid | |
generator: | |
strategy: NONE | |
embedded: | |
username: | |
class: Acme\Project\Model\User\ValueObject\Username | |
columnPrefix: false |
This file contains hidden or 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
Acme\Project\Model\User\ValueObject\Username: | |
type: embeddable | |
fields: | |
value: | |
type: string | |
column: username |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment