1 | <?php |
||
25 | class ObjectMapper |
||
26 | { |
||
27 | /** |
||
28 | * Provider of mapping definition |
||
29 | * |
||
30 | * @var DefinitionProviderInterface |
||
31 | */ |
||
32 | protected $definitionProvider; |
||
33 | |||
34 | /** |
||
35 | * Required identifier handler |
||
36 | * Must always be present regardless of other handlers |
||
37 | * |
||
38 | * @var IdentifierHandlerInterface |
||
39 | */ |
||
40 | protected $identifierHandler; |
||
41 | |||
42 | /** |
||
43 | * Required type handler |
||
44 | * Must always be present regardless of other handlers |
||
45 | * |
||
46 | * @var TypeHandlerInterface |
||
47 | */ |
||
48 | protected $typeHandler; |
||
49 | |||
50 | /** |
||
51 | * Mapping handlers |
||
52 | * |
||
53 | * @var HandlerInterface[] |
||
54 | */ |
||
55 | protected $handlers = []; |
||
56 | |||
57 | /** |
||
58 | * ObjectMapper constructor. |
||
59 | * |
||
60 | * @param DefinitionProviderInterface $definitionProvider |
||
61 | * @param IdentifierHandlerInterface $identifierHandler |
||
62 | * @param TypeHandlerInterface $typeHandler |
||
63 | */ |
||
64 | 3 | public function __construct( |
|
73 | |||
74 | /** |
||
75 | * Add mapping handler |
||
76 | * |
||
77 | * @param HandlerInterface $handler |
||
78 | */ |
||
79 | 2 | public function addHandler(HandlerInterface $handler) |
|
83 | |||
84 | /** |
||
85 | * Map object's data to resource |
||
86 | * |
||
87 | * @param mixed $object |
||
88 | * @return ResourceObject |
||
89 | */ |
||
90 | 1 | public function toResource($object): ResourceObject |
|
106 | |||
107 | /** |
||
108 | * Map object's identification to resource-identifier |
||
109 | * |
||
110 | * @param $object |
||
111 | * @return ResourceIdentifierObject |
||
112 | */ |
||
113 | 1 | public function toResourceIdentifier($object): ResourceIdentifierObject |
|
122 | |||
123 | /** |
||
124 | * Map resource's data to provided object |
||
125 | * |
||
126 | * @param mixed $object |
||
127 | * @param ResourceObject $resource |
||
128 | */ |
||
129 | 1 | public function fromResource($object, ResourceObject $resource) |
|
140 | |||
141 | /** |
||
142 | * Resolve type of resource |
||
143 | * |
||
144 | * @param $object |
||
145 | * @param MappingContext $context |
||
146 | * @return string |
||
147 | */ |
||
148 | 2 | protected function resolveType($object, MappingContext $context): string |
|
158 | |||
159 | /** |
||
160 | * Create mapping context for given class |
||
161 | * |
||
162 | * @param string $class |
||
163 | * @return MappingContext |
||
164 | */ |
||
165 | 3 | protected function createContext(string $class): MappingContext |
|
171 | } |