1 | <?php |
||
23 | class ObjectMapper |
||
24 | { |
||
25 | /** |
||
26 | * Required identifier handler |
||
27 | * Must always be present regardless of other handlers |
||
28 | * |
||
29 | * @var IdentifierHandlerInterface |
||
30 | */ |
||
31 | protected $identifierHandler; |
||
32 | |||
33 | /** |
||
34 | * Required type handler |
||
35 | * Must always be present regardless of other handlers |
||
36 | * |
||
37 | * @var TypeHandlerInterface |
||
38 | */ |
||
39 | protected $typeHandler; |
||
40 | |||
41 | /** |
||
42 | * Mapping handlers |
||
43 | * |
||
44 | * @var HandlerInterface[] |
||
45 | */ |
||
46 | protected $handlers = []; |
||
47 | |||
48 | /** |
||
49 | * ObjectMapper constructor. |
||
50 | * |
||
51 | * @param IdentifierHandlerInterface $identifierHandler |
||
52 | * @param TypeHandlerInterface $typeHandler |
||
53 | */ |
||
54 | 2 | public function __construct(IdentifierHandlerInterface $identifierHandler, TypeHandlerInterface $typeHandler) |
|
59 | |||
60 | /** |
||
61 | * Add mapping handler |
||
62 | * |
||
63 | * @param HandlerInterface $handler |
||
64 | */ |
||
65 | 2 | public function addHandler(HandlerInterface $handler) |
|
69 | |||
70 | /** |
||
71 | * Map object's data to resource |
||
72 | * |
||
73 | * @param mixed $object |
||
74 | * @return ResourceObject |
||
75 | */ |
||
76 | 1 | public function toResource($object): ResourceObject |
|
90 | |||
91 | /** |
||
92 | * Map resource's data to provided object |
||
93 | * |
||
94 | * @param mixed $object |
||
95 | * @param ResourceObject $resource |
||
96 | */ |
||
97 | 1 | public function fromResource($object, ResourceObject $resource) |
|
106 | } |