すべてのプロパティが割り当てられた状態でドメイン オブジェクトを初期化する必要があるのはなぜですか?
代わりに、空のDomain Objectを作成してください。prepare()
実行するメソッドがある場合は、工場でチェックすることができます。ああ、DAOを使用している場合は、マッパーと直接対話する代わりに、ドメイン オブジェクトに適切なDAOを構築して注入することをお勧めします。
値の割り当てはServiceで行う必要があります。通常のセッターを使用。
いくつかの例:
既存の記事を取得しています
public function retrieveArticle( $id )
{
$mapper = $this->mapperFactory->create('Article');
$article = $this->domainFactory->create('Article');
$article->setId( $id );
$mapper->fetch( $article );
$this->currentArticle = $article;
}
新しいコメントを投稿しています
public function addComment( $id, $content )
{
$mapper = $this->mapperFactory->create('article');
$article = $this->domainFactory->create('Article');
$comment = $this->domainFactory->create('Comment');
$comment->setContent( $content );
$comment->setAuthor( /* user object that you retrieved from Recognition service */ );
$article->setId( $id );
$article->addComment( $comment );
// or you might retrieve the ID of currently view article
// and assign it .. depends how you build it all
$mapper->store( $article ); // or
}
ユーザー入力を渡す
public function getArticle( $request )
{
$library = $this->serviceFactory->build('Library');
$library->retrieveArticle( $request->getParameter('articleId'));
}