Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP DataMapper with multiple persistence layers
    text
    copied!<p>I am writing a system in PHP that has to write to three persistence layers:</p> <ul> <li>One web service</li> <li>Two databases (one mysql one mssql)</li> </ul> <p>The reason for this is legacy systems and cannot be changed.</p> <p>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:</p> <pre class="lang-php prettyprint-override"><code>&lt;?php $service = $factory-&gt;getService()-&gt;create($entity); ?&gt; </code></pre> <p>Below is some contrived and cut down code for brevity:</p> <pre class="lang-php prettyprint-override"><code>&lt;?php class Post extends AbstractService { protected $_mapper; public function create(Entity $post) { return $this-&gt;_mapper-&gt;create($post); } } class AbstractMapper { protected $_persistence; public function create(Entity $entity) { $data = $this-&gt;_prepareForPersistence($entity); return $this-&gt;_persistence-&gt;create($data); } } ?&gt; </code></pre> <p>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.</p> <p>I see it as having three options:</p> <ol> <li>Inject three mappers into the Service and call create on each</li> <li>$_mapper is an array/collection and it iterates through them calling create on each</li> <li>$_mapper is actually a container object that acts as a further proxy and calls create on each</li> </ol> <p>Something strikes me as wrong with each of these solutions and would appreciate any feedback/recognised design patterns that might fit this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload