KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am writing a system in PHP that has to write to three persistence layers: One web service Two databases (one mysql one mssql) The reason for this is legacy systems and cannot be changed. I am wanting to use the DataMapper pattern and I am trying to establish the best way to achieve what I want. I have an interface like follows: <?php $service = $factory->getService()->create($entity); ?> Below is some contrived and cut down code for brevity: <?php class Post extends AbstractService { protected $_mapper; public function create(Entity $post) { return $this->_mapper->create($post); } } class AbstractMapper { protected $_persistence; public function create(Entity $entity) { $data = $this->_prepareForPersistence($entity); return $this->_persistence->create($data); } } ?> My question is that because there are three persistence layers, there will also therefore likely be a need for three mappers for each. I'd like a clean design pattern inspired interface to make this work. I see it as having three options: Inject three mappers into the Service and call create on each $_mapper is an array/collection and it iterates through them calling create on each $_mapper is actually a container object that acts as a further proxy and calls create on each Something strikes me as wrong with each of these solutions and would appreciate any feedback/recognised design patterns that might fit this.
Tags (comma-separated)
Save Edits
Cancel