Skip to content

Instantly share code, notes, and snippets.

@dadamssg
Created July 13, 2015 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadamssg/12cdf4f8f771383f45cb to your computer and use it in GitHub Desktop.
Save dadamssg/12cdf4f8f771383f45cb to your computer and use it in GitHub Desktop.
<?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