Last active
November 2, 2015 10:38
-
-
Save dadamssg/25714381e97220147ce2 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\Value; | |
use Acme\Project\Model\Core\Validation\Assert; | |
final class PhoneNumber | |
{ | |
/** | |
* @var string | |
*/ | |
private $value; | |
/** | |
* @param string $phoneNumber | |
*/ | |
public function __construct($phoneNumber) | |
{ | |
Assert::string($phoneNumber, "Invalid phone number."); | |
$this->value = $phoneNumber; | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return $this->value ?: ''; // required because doctrine disables the constructor when creating | |
} | |
} |
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 | |
table: user | |
id: | |
id: | |
type: guid | |
generator: | |
strategy: none | |
fields: | |
registeredAt: | |
type: datetime | |
column: registered_at | |
embedded: | |
phoneNumber: | |
class: Acme\Project\Model\User\Value\PhoneNumber | |
columnPrefix: false | |
nullable: true # <--- new option |
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\Value\PhoneNumber: | |
type: embeddable | |
fields: | |
value: | |
type: string | |
column: phone_number | |
nullable: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment