Skip to content

Instantly share code, notes, and snippets.

@l3l0
Created April 3, 2014 09:58
Show Gist options
  • Save l3l0/9951802 to your computer and use it in GitHub Desktop.
Save l3l0/9951802 to your computer and use it in GitHub Desktop.
<?php
namespace Sk\CmsBundle\Entity;
class Contact
{
private $name;
public function __construct(Contact\ContactName $name)
{
$this->name = $name->toString();
}
public function changeName(Contact\ContactName $name)
{
$currentName = new ContactName($this->name);
if ($currentName->isDifferentFrom($name)) {
$this->name = $name->toString();
}
}
}
<?php
namespace Sk\CmsBundle\Entity\Contact;
class ContactName
{
private $name;
public function __construct($name)
{
if (false === $value || (empty($value) && '0' != $value)) {
throw new \InvalidArgumentException('Cannot create contact with empty name');
}
$this->name = $name;
}
public function toString()
{
return $this->name;
}
public function isDifferentFrom(ContactName $name)
{
return $this->name !== $name->toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment