8016ef8b8cc13693ce368241f4c3f199d860ef6a
[m6w6/pq-gateway] / lib / pq / Mapper / Storage.php
1 <?php
2
3 namespace pq\Mapper;
4
5 use pq\Gateway\Table;
6
7 class Storage implements StorageInterface
8 {
9 /**
10 * The mapping of this storage
11 * @var MapInterface
12 */
13 var $map;
14
15 /**
16 * The underlying table gateway
17 * @var Table
18 */
19 private $gateway;
20
21 /**
22 * Create a storage for $map
23 * @param MapInterface $map
24 */
25 function __construct(MapInterface $map) {
26 $this->map = $map;
27 $this->gateway = $map->getGateway();
28 }
29
30 /**
31 * Find
32 * @param array $where
33 * @param string $order
34 * @param int $limit
35 * @param int $offset
36 * @return object[]
37 */
38 function find($where = [], $order = null, $limit = null, $offset = null) {
39 /* @var pq\Gateway\Rowset $rowset */
40 $rowset = $this->gateway->find($where, $order, $limit, $offset);
41 return $this->map->mapAll($rowset);
42 }
43
44 /**
45 * Delete
46 * @param object $object
47 */
48 function delete($object) {
49 $cache = $this->map->getObjects();
50 $row = $cache->asRow($object)->delete();
51 $cache->resetObject($row);
52 $cache->resetRow($object);
53 }
54
55 /**
56 * Save
57 * @param object $object
58 */
59 function save($object) {
60 $this->map->unmap($object);
61 }
62 }