1 | <?php |
||
28 | class DocumentBuilder |
||
29 | { |
||
30 | /** |
||
31 | * @var ObjectMapper |
||
32 | */ |
||
33 | protected $mapper; |
||
34 | |||
35 | /** |
||
36 | * Link-repositories provider |
||
37 | * |
||
38 | * @var RepositoryProvider |
||
39 | */ |
||
40 | protected $repositoryProvider; |
||
41 | |||
42 | /** |
||
43 | * Builder constructor. |
||
44 | * |
||
45 | * @param ObjectMapper $mapper |
||
46 | * @param RepositoryProvider $repositoryProvider |
||
47 | */ |
||
48 | 10 | public function __construct(ObjectMapper $mapper, RepositoryProvider $repositoryProvider) |
|
53 | |||
54 | /** |
||
55 | * Build a document by a view |
||
56 | * |
||
57 | * @param AbstractJsonApiView $view |
||
58 | * @return AbstractDocument |
||
59 | */ |
||
60 | 9 | public function build(AbstractJsonApiView $view): AbstractDocument |
|
73 | |||
74 | /** |
||
75 | * Create a document by a view |
||
76 | * |
||
77 | * @param AbstractJsonApiView $view |
||
78 | * @return AbstractDocument |
||
79 | */ |
||
80 | 9 | protected function createDocument(AbstractJsonApiView $view): AbstractDocument |
|
92 | |||
93 | /** |
||
94 | * Handle single object Json API view |
||
95 | * |
||
96 | * @param JsonApiObjectView $view |
||
97 | * @return SingleResourceDocument |
||
98 | */ |
||
99 | 5 | protected function createSingleResourceDocument(JsonApiObjectView $view): SingleResourceDocument |
|
112 | |||
113 | /** |
||
114 | * Handle object-iterator |
||
115 | * |
||
116 | * @param JsonApiIteratorView $view |
||
117 | * @return ResourceCollectionDocument |
||
118 | */ |
||
119 | 4 | protected function createCollectionDocument(JsonApiIteratorView $view): ResourceCollectionDocument |
|
137 | |||
138 | /** |
||
139 | * Handle object |
||
140 | * |
||
141 | * @param $object |
||
142 | * @return ResourceObject |
||
143 | */ |
||
144 | 9 | protected function handleObject($object): ResourceObject |
|
152 | |||
153 | /** |
||
154 | * Handle supposed to be included to document resources |
||
155 | * |
||
156 | * @param AbstractDocument $document |
||
157 | * @param IncludedObjectsAwareInterface $view |
||
158 | */ |
||
159 | 9 | protected function handleIncludedResources(AbstractDocument $document, IncludedObjectsAwareInterface $view) |
|
167 | |||
168 | /** |
||
169 | * Handle links of document |
||
170 | * |
||
171 | * @param AbstractJsonApiView $view |
||
172 | * @param AbstractDocument $document |
||
173 | */ |
||
174 | 9 | protected function handleDocumentLinks(AbstractDocument $document, AbstractJsonApiView $view) |
|
196 | } |