Created
July 13, 2015 16:03
-
-
Save dadamssg/12cdf4f8f771383f45cb 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
<?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 ?: ''; // <-- important, Doctrine always creates the embeddables even if their value is null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment