Why do you want to initialize a Domain Object with all the properties assigned?
Instead just create an empty Domain Object. You might in the factory check, if it has prepare()
method to execute. Oh .. and if you are using DAO, instead of directly interacting with Mappers, you might want to construct and inject the appropriate DAO in your Domain Object.
The assignment of values should just happen in the Service. By the use of ordinary setters.
Some examples:
Retrieving existing article
public function retrieveArticle( $id )
{
$mapper = $this->mapperFactory->create('Article');
$article = $this->domainFactory->create('Article');
$article->setId( $id );
$mapper->fetch( $article );
$this->currentArticle = $article;
}
Posting new comment
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
}
Passing user input
public function getArticle( $request )
{
$library = $this->serviceFactory->build('Library');
$library->retrieveArticle( $request->getParameter('articleId'));
}