Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
1 | <?php |
2 | |
3 | namespace Flow\Data; |
4 | |
5 | /** |
6 | * Interface for converting back and forth between a database row and |
7 | * a domain model. |
8 | */ |
9 | interface ObjectMapper { |
10 | /** |
11 | * Convert $object from the domain model to its db row |
12 | * |
13 | * @param object $object |
14 | * @return array |
15 | */ |
16 | public function toStorageRow( $object ); |
17 | |
18 | /** |
19 | * Convert a db row to its domain model. Object passing is intended for |
20 | * updating the object to match a changed storage representation. |
21 | * |
22 | * @param array $row Assoc array representing the domain model |
23 | * @param object|null $object The domain model to populate, creates when null |
24 | * @return object The domain model populated with $row |
25 | * @throws \Exception When object is the wrong class for the mapper |
26 | */ |
27 | public function fromStorageRow( array $row, $object = null ); |
28 | |
29 | /** |
30 | * Check internal cache for previously unserialized objects |
31 | * |
32 | * @param array $primaryKey |
33 | * @return object|null |
34 | */ |
35 | public function get( array $primaryKey ); |
36 | |
37 | /** |
38 | * Accepts a row representing domain model & returns that same row, |
39 | * normalized. It'll roundtrip the row from- & toStorageRow to cleanup data. |
40 | * We want to make sure that data type differences cause no false positives, |
41 | * like $row containing strings, & new row has integers with the same value. |
42 | * |
43 | * @param array $row Assoc array representing the domain model |
44 | * @return array Normalized row |
45 | */ |
46 | public function normalizeRow( array $row ); |
47 | |
48 | /** |
49 | * Clear any internally cached information |
50 | */ |
51 | public function clear(); |
52 | } |