Why do you want to initialize a Domain Object with all assigned properties?
Instead, just create an empty domain object. You can check the factory if it has a prepare()
method to execute. Oh .. and if you use DAO , instead of directly interacting with Mappers , you can create and enter the corresponding DAO in your domain object.
Assignment of values should occur only in Service . Using regular setters.
Some examples:
Retrieving an 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 a 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( ); $article->setId( $id ); $article->addComment( $comment );
Passing User Input
public function getArticle( $request ) { $library = $this->serviceFactory->build('Library'); $library->retrieveArticle( $request->getParameter('articleId')); }
source share