Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
BasicObjectMapper | |
0.00% |
0 / 9 |
|
0.00% |
0 / 7 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
model | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toStorageRow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
fromStorageRow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
normalizeRow | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
clear | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Data\Mapper; |
4 | |
5 | use Flow\Data\ObjectMapper; |
6 | |
7 | /** |
8 | * Simplest possible implementation of ObjectMapper delgates |
9 | * execution to closures passed in the constructor. |
10 | * |
11 | * This can be used to keep the mapping logic in static methods |
12 | * within the model as so: |
13 | * |
14 | * $userMapper = new BasicObjectMapper( |
15 | * [ 'User', 'toStorageRow' ], |
16 | * [ 'User', 'fromStorageRow' ], |
17 | * ); |
18 | */ |
19 | class BasicObjectMapper implements ObjectMapper { |
20 | /** @var callable */ |
21 | protected $toStorageRow; |
22 | |
23 | /** @var callable */ |
24 | protected $fromStorageRow; |
25 | |
26 | public function __construct( $toStorageRow, $fromStorageRow ) { |
27 | $this->toStorageRow = $toStorageRow; |
28 | $this->fromStorageRow = $fromStorageRow; |
29 | } |
30 | |
31 | public static function model( $className ) { |
32 | return new self( [ $className, 'toStorageRow' ], [ $className, 'fromStorageRow' ] ); |
33 | } |
34 | |
35 | public function toStorageRow( $object ) { |
36 | return ( $this->toStorageRow )( $object ); |
37 | } |
38 | |
39 | public function fromStorageRow( array $row, $object = null ) { |
40 | return ( $this->fromStorageRow )( $row, $object ); |
41 | } |
42 | |
43 | public function get( array $pk ) { |
44 | return null; |
45 | } |
46 | |
47 | /** |
48 | * @inheritDoc |
49 | */ |
50 | public function normalizeRow( array $row ) { |
51 | $object = $this->fromStorageRow( $row ); |
52 | return $this->toStorageRow( $object ); |
53 | } |
54 | |
55 | public function clear() { |
56 | // noop |
57 | } |
58 | } |