Skip to content

Instantly share code, notes, and snippets.

@dadamssg
Last active November 2, 2015 10:38
Show Gist options
  • Save dadamssg/25714381e97220147ce2 to your computer and use it in GitHub Desktop.
Save dadamssg/25714381e97220147ce2 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 ?: ''; // required because doctrine disables the constructor when creating
}
}
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
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