Created
April 3, 2014 09:58
-
-
Save l3l0/9951802 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 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(); | |
} | |
} | |
} |
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 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