Skip to content

Instantly share code, notes, and snippets.

@Akii
Created March 13, 2015 20:23
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 Akii/f973ae33e4426f3854dc to your computer and use it in GitHub Desktop.
Save Akii/f973ae33e4426f3854dc to your computer and use it in GitHub Desktop.
class Author implements ValueObject {
/**
* @var string
*/
protected $memberId;
// constructor
/**
* @param string $topic
* @return Thread
*/
public function openThread($topic) {
return Thread::open($this->memberId, $topic);
}
// getter
}
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;
}
}
class Thread implements AggregateRoot {
/**
* @var string
*/
protected $threadId;
/**
* @var Author
*/
protected $author;
/**
* @var string
*/
protected $topic;
static public function open(Author $author, $topic) {...
}
// 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