Created
March 13, 2015 20:23
-
-
Save Akii/f973ae33e4426f3854dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class MemberAdapter implements Singleton { | |
/** | |
* Injected with DI | |
* @var Membership\MemberRepository | |
*/ | |
protected $memberRepository; | |
/** | |
* @param string $memberId | |
* @return NULL|Author | |
*/ | |
public function toAuthor($memberId) { | |
$member = $this->memberRepository->findById($memberId); | |
return ($member !== NULL) ? new Author($memberId) : NULL; | |
} | |
} |
This file contains hidden or 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
class Thread implements AggregateRoot { | |
/** | |
* @var string | |
*/ | |
protected $threadId; | |
/** | |
* @var Author | |
*/ | |
protected $author; | |
/** | |
* @var string | |
*/ | |
protected $topic; | |
static public function open(Author $author, $topic) {... | |
} |
This file contains hidden or 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
// Application Service | |
class ThreadService implements Singleton { | |
// injected MemberAdapter | |
// inject ThreadRepository | |
/** | |
* @param string $memberId | |
* @param string $topic | |
* @return string Identifier of the opened thread | |
*/ | |
public function openThread($memberId, $topic) { | |
$author = $this->memberAdapter->toAuthor($memberId); | |
if ($author === NULL) { | |
throw new UnknownAuthorException(.. | |
} | |
//$thread = Thread::open($author->getMemberId(), $topic); | |
$thread = $author->openThread($topic); | |
$this->threadRepository->save($thread); | |
return $thread->getThreadId(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment