1 | <?php |
||
16 | abstract class AbstractObjectMapper implements ObjectMapperInterface |
||
17 | { |
||
18 | /** |
||
19 | * Identifier of resource handler |
||
20 | * |
||
21 | * @var IdentifierHandlerInterface |
||
22 | */ |
||
23 | protected $identifierHandler; |
||
24 | |||
25 | /** |
||
26 | * Type of resource handler |
||
27 | * |
||
28 | * @var TypeHandlerInterface |
||
29 | */ |
||
30 | protected $typeHandler; |
||
31 | |||
32 | /** |
||
33 | * AbstractObjectMapper constructor. |
||
34 | * |
||
35 | * @param IdentifierHandlerInterface $identifierHandler |
||
36 | * @param TypeHandlerInterface $typeHandler |
||
37 | */ |
||
38 | 2 | public function __construct(IdentifierHandlerInterface $identifierHandler, TypeHandlerInterface $typeHandler) |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 1 | final public function toResource($object): ResourceObject |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 1 | final public function fromResource($object, ResourceObject $resource) |
|
66 | |||
67 | /** |
||
68 | * Map properties of object to an array |
||
69 | * [name => value] |
||
70 | * |
||
71 | * @param mixed $object |
||
72 | * @return array |
||
73 | */ |
||
74 | abstract protected function toArray($object): array; |
||
75 | |||
76 | /** |
||
77 | * Map an array of data to object |
||
78 | * [name => value] |
||
79 | * |
||
80 | * @param mixed $object |
||
81 | * @param array $data |
||
82 | */ |
||
83 | abstract protected function fromArray($object, array $data); |
||
84 | } |