data mapper POC
[m6w6/pq-gateway] / lib / pq / Mapper / Storage.php
1 <?php
2
3 namespace pq\Mapper;
4
5 class Storage implements StorageInterface
6 {
7 /**
8 * @var string
9 */
10 private $class;
11
12 /**
13 * @var \pq\Mapper\Mapper
14 */
15 private $mapper;
16
17 /**
18 *
19 * @var pq\Mapper\MapInterface
20 */
21 private $mapping;
22
23 /**
24 * @var \pq\Gateway\Table
25 */
26 private $gateway;
27
28 function __construct(Mapper $mapper, $class) {
29 $this->class = $class;
30 $this->mapper = $mapper;
31 $this->mapping = $mapper->mapOf($class);
32 $this->gateway = $this->mapping->getGateway();
33 }
34
35 function getMapper() {
36 return $this->mapper;
37 }
38
39 function find($where = [], $order = null, $limit = null, $offset = null) {
40 /* @var pq\Gateway\Rowset $rowset */
41 $rowset = $this->gateway->find($where, $order, $limit, $offset);
42 return $this->mapping->mapAll($rowset);
43 }
44
45 function delete($object) {
46 $cache = $this->mapping->getObjects();
47 $row = $cache->asRow($object)->delete();
48 $cache->resetObject($row);
49 $cache->resetRow($object);
50 }
51
52 function persist($object) {
53 $this->mapping->unmap($object);
54 }
55
56 }