|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace POData\ObjectModel; |
|
4
|
|
|
|
|
5
|
|
|
use POData\Common\ODataConstants; |
|
6
|
|
|
use POData\Common\InvalidOperationException; |
|
7
|
|
|
use POData\Providers\Query\QueryType; |
|
8
|
|
|
use POData\UriProcessor\ResourcePathProcessor\SegmentParser\TargetSource; |
|
9
|
|
|
use POData\UriProcessor\RequestDescription; |
|
10
|
|
|
use POData\IService; |
|
11
|
|
|
use POData\Providers\Metadata\ResourceType; |
|
12
|
|
|
use POData\Providers\Metadata\ResourceTypeKind; |
|
13
|
|
|
use POData\Providers\Metadata\ResourcePropertyKind; |
|
14
|
|
|
use POData\Providers\Metadata\ResourceProperty; |
|
15
|
|
|
use POData\Providers\ProvidersWrapper; |
|
16
|
|
|
use POData\Providers\Metadata\Type\Binary; |
|
17
|
|
|
use POData\Providers\Metadata\Type\Boolean; |
|
18
|
|
|
use POData\Providers\Metadata\Type\StringType; |
|
19
|
|
|
use POData\Providers\Metadata\Type\DateTime; |
|
20
|
|
|
use POData\Common\ODataException; |
|
21
|
|
|
use POData\Common\Messages; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ObjectModelSerializer |
|
25
|
|
|
* @package POData\ObjectModel |
|
26
|
|
|
*/ |
|
27
|
|
|
class ObjectModelSerializer extends ObjectModelSerializerBase |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Creates new instance of ObjectModelSerializer. |
|
31
|
|
|
* |
|
32
|
|
|
* @param IService $service |
|
33
|
|
|
* |
|
34
|
|
|
* @param RequestDescription $request the request submitted by the client. |
|
35
|
|
|
* |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(IService $service, RequestDescription $request) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct($service, $request); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Write a top level entry resource. |
|
44
|
|
|
* |
|
45
|
|
|
* @param mixed $entryObject Reference to the entry object to be written. |
|
46
|
|
|
* |
|
47
|
|
|
* @return ODataEntry |
|
48
|
|
|
*/ |
|
49
|
|
|
public function writeTopLevelElement($entryObject) |
|
50
|
|
|
{ |
|
51
|
|
|
$requestTargetSource = $this->request->getTargetSource(); |
|
52
|
|
|
|
|
53
|
|
|
$resourceType = null; |
|
|
|
|
|
|
54
|
|
View Code Duplication |
if ($requestTargetSource == TargetSource::ENTITY_SET) { |
|
|
|
|
|
|
55
|
|
|
$resourceType = $this->request->getTargetResourceType(); |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->assert( |
|
58
|
|
|
$requestTargetSource == TargetSource::PROPERTY, |
|
59
|
|
|
'$requestTargetSource == TargetSource::PROPERTY' |
|
60
|
|
|
); |
|
61
|
|
|
$resourceProperty = $this->request->getProjectedProperty(); |
|
62
|
|
|
//$this->assert($resourceProperty->getKind() == ResourcePropertyKind::RESOURCE_REFERENCE, '$resourceProperty->getKind() == ResourcePropertyKind::RESOURCE_REFERENCE'); |
|
|
|
|
|
|
63
|
|
|
$resourceType = $resourceProperty->getResourceType(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$needPop = $this->pushSegmentForRoot(); |
|
67
|
|
|
$entry = $this->_writeEntryElement( |
|
68
|
|
|
$entryObject, |
|
69
|
|
|
$resourceType, |
|
70
|
|
|
$this->request->getRequestUrl()->getUrlAsString(), |
|
71
|
|
|
$this->request->getContainerName() |
|
72
|
|
|
); |
|
73
|
|
|
$this->popSegment($needPop); |
|
74
|
|
|
return $entry; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Write top level feed element. |
|
79
|
|
|
* |
|
80
|
|
|
* @param array &$entryObjects Array of entry resources to be written. |
|
81
|
|
|
* |
|
82
|
|
|
* @return ODataFeed. |
|
|
|
|
|
|
83
|
|
|
*/ |
|
84
|
|
|
public function writeTopLevelElements(&$entryObjects) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->assert(is_array($entryObjects), 'is_array($entryObjects)'); |
|
87
|
|
|
$requestTargetSource = $this->request->getTargetSource(); |
|
88
|
|
|
$title = null; |
|
|
|
|
|
|
89
|
|
|
if ($requestTargetSource == TargetSource::ENTITY_SET) { |
|
90
|
|
|
$title = $this->request->getContainerName(); |
|
91
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
92
|
|
|
$this->assert( |
|
93
|
|
|
$requestTargetSource == TargetSource::PROPERTY, |
|
94
|
|
|
'$requestTargetSource == TargetSource::PROPERTY' |
|
95
|
|
|
); |
|
96
|
|
|
$resourceProperty = $this->request->getProjectedProperty(); |
|
97
|
|
|
$this->assert( |
|
98
|
|
|
$resourceProperty->getKind() == ResourcePropertyKind::RESOURCESET_REFERENCE, |
|
99
|
|
|
'$resourceProperty->getKind() == ResourcePropertyKind::RESOURCESET_REFERENCE' |
|
100
|
|
|
); |
|
101
|
|
|
$title = $resourceProperty->getName(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$relativeUri = $this->request->getIdentifier(); |
|
105
|
|
|
$feed = new ODataFeed(); |
|
106
|
|
|
|
|
107
|
|
|
if ($this->request->queryType == QueryType::ENTITIES_WITH_COUNT()) { |
|
108
|
|
|
$feed->rowCount = $this->request->getCountValue(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$needPop = $this->pushSegmentForRoot(); |
|
112
|
|
|
$targetResourceType = $this->request->getTargetResourceType(); |
|
113
|
|
|
$this->_writeFeedElements( |
|
114
|
|
|
$entryObjects, |
|
115
|
|
|
$targetResourceType, |
|
|
|
|
|
|
116
|
|
|
$title, |
|
117
|
|
|
$this->request->getRequestUrl()->getUrlAsString(), |
|
118
|
|
|
$relativeUri, |
|
119
|
|
|
$feed |
|
120
|
|
|
); |
|
121
|
|
|
$this->popSegment($needPop); |
|
122
|
|
|
return $feed; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Write top level url element. |
|
127
|
|
|
* |
|
128
|
|
|
* @param mixed $entryObject The entry resource whose url to be written. |
|
129
|
|
|
* |
|
130
|
|
|
* @return ODataURL |
|
131
|
|
|
*/ |
|
132
|
|
|
public function writeUrlElement($entryObject) |
|
133
|
|
|
{ |
|
134
|
|
|
$url = new ODataURL(); |
|
135
|
|
|
if (!is_null($entryObject)) { |
|
136
|
|
|
$currentResourceType = $this->getCurrentResourceSetWrapper()->getResourceType(); |
|
137
|
|
|
$relativeUri = $this->getEntryInstanceKey( |
|
138
|
|
|
$entryObject, |
|
139
|
|
|
$currentResourceType, |
|
140
|
|
|
$this->getCurrentResourceSetWrapper()->getName() |
|
141
|
|
|
); |
|
142
|
|
|
|
|
143
|
|
|
$url->url = rtrim($this->absoluteServiceUri, '/') . '/' . $relativeUri; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $url; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Write top level url collection. |
|
151
|
|
|
* |
|
152
|
|
|
* @param array $entryObjects Array of entry resources |
|
153
|
|
|
* whose url to be written. |
|
154
|
|
|
* |
|
155
|
|
|
* @return ODataURLCollection |
|
156
|
|
|
*/ |
|
157
|
|
|
public function writeUrlElements($entryObjects) |
|
158
|
|
|
{ |
|
159
|
|
|
$urls = new ODataURLCollection(); |
|
160
|
|
|
if (!empty($entryObjects)) { |
|
161
|
|
|
$i = 0; |
|
162
|
|
|
foreach ($entryObjects as $entryObject) { |
|
163
|
|
|
$urls->urls[$i] = $this->writeUrlElement($entryObject); |
|
164
|
|
|
$i++; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
if ($i > 0 && $this->needNextPageLink(count($entryObjects))) { |
|
168
|
|
|
$urls->nextPageLink = $this->getNextLinkUri($entryObjects[$i - 1], $this->request->getRequestUrl()->getUrlAsString()); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
if ($this->request->queryType == QueryType::ENTITIES_WITH_COUNT()) { |
|
173
|
|
|
$urls->count = $this->request->getCountValue(); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $urls; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Write top level complex resource. |
|
181
|
|
|
* |
|
182
|
|
|
* @param mixed &$complexValue The complex object to be |
|
183
|
|
|
* written. |
|
184
|
|
|
* @param string $propertyName The name of the |
|
185
|
|
|
* complex property. |
|
186
|
|
|
* @param ResourceType &$resourceType Describes the type of |
|
187
|
|
|
* complex object. |
|
188
|
|
|
* |
|
189
|
|
|
* @return ODataPropertyContent |
|
190
|
|
|
*/ |
|
191
|
|
|
public function writeTopLevelComplexObject( |
|
192
|
|
|
&$complexValue, |
|
193
|
|
|
$propertyName, |
|
194
|
|
|
ResourceType &$resourceType |
|
195
|
|
|
) { |
|
196
|
|
|
$propertyContent = new ODataPropertyContent(); |
|
197
|
|
|
$this->_writeComplexValue( |
|
198
|
|
|
$complexValue, |
|
199
|
|
|
$propertyName, $resourceType, null, |
|
200
|
|
|
$propertyContent |
|
201
|
|
|
); |
|
202
|
|
|
|
|
203
|
|
|
return $propertyContent; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Write top level bag resource. |
|
208
|
|
|
* |
|
209
|
|
|
* @param mixed &$BagValue The bag object to be |
|
210
|
|
|
* written. |
|
211
|
|
|
* @param string $propertyName The name of the |
|
212
|
|
|
* bag property. |
|
213
|
|
|
* @param ResourceType &$resourceType Describes the type of |
|
214
|
|
|
* bag object. |
|
215
|
|
|
* |
|
216
|
|
|
* @return ODataPropertyContent |
|
217
|
|
|
*/ |
|
218
|
|
|
public function writeTopLevelBagObject( |
|
219
|
|
|
&$BagValue, |
|
220
|
|
|
$propertyName, |
|
221
|
|
|
ResourceType &$resourceType |
|
222
|
|
|
) { |
|
223
|
|
|
|
|
224
|
|
|
$propertyContent = new ODataPropertyContent(); |
|
225
|
|
|
$this->_writeBagValue( |
|
226
|
|
|
$BagValue, |
|
227
|
|
|
$propertyName, $resourceType, null, |
|
228
|
|
|
$propertyContent |
|
229
|
|
|
); |
|
230
|
|
|
|
|
231
|
|
|
return $propertyContent; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Write top level primitive value. |
|
236
|
|
|
* |
|
237
|
|
|
* @param mixed &$primitiveValue The primitve value to be |
|
238
|
|
|
* written. |
|
239
|
|
|
* @param ResourceProperty &$resourceProperty Resource property |
|
240
|
|
|
* describing the |
|
241
|
|
|
* primitive property |
|
242
|
|
|
* to be written. |
|
243
|
|
|
* |
|
244
|
|
|
* @return ODataPropertyContent |
|
245
|
|
|
*/ |
|
246
|
|
|
public function writeTopLevelPrimitive( |
|
247
|
|
|
&$primitiveValue, |
|
248
|
|
|
ResourceProperty &$resourceProperty |
|
249
|
|
|
) { |
|
250
|
|
|
$propertyContent = new ODataPropertyContent(); |
|
251
|
|
|
$propertyContent->properties[] = new ODataProperty(); |
|
252
|
|
|
$this->_writePrimitiveValue( |
|
253
|
|
|
$primitiveValue, |
|
254
|
|
|
$resourceProperty, |
|
255
|
|
|
$propertyContent->properties[0] |
|
256
|
|
|
); |
|
257
|
|
|
|
|
258
|
|
|
return $propertyContent; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Write an entry element. |
|
263
|
|
|
* |
|
264
|
|
|
* @param mixed $entryObject Object representing entry element. |
|
265
|
|
|
* @param ResourceType $resourceType Expected type of the entry object. |
|
266
|
|
|
* @param string $absoluteUri Absolute uri of the entry element. |
|
267
|
|
|
* @param string $relativeUri Relative uri of the entry element. |
|
268
|
|
|
* |
|
269
|
|
|
* @return ODataEntry |
|
270
|
|
|
*/ |
|
271
|
|
|
private function _writeEntryElement( |
|
272
|
|
|
$entryObject, |
|
273
|
|
|
ResourceType $resourceType, |
|
274
|
|
|
$absoluteUri, |
|
|
|
|
|
|
275
|
|
|
$relativeUri |
|
|
|
|
|
|
276
|
|
|
) { |
|
277
|
|
|
$entry = new ODataEntry(); |
|
278
|
|
|
$entry->resourceSetName = $this->getCurrentResourceSetWrapper()->getName(); |
|
279
|
|
|
|
|
280
|
|
|
if (is_null($entryObject)) { |
|
|
|
|
|
|
281
|
|
|
//According to atom standard an empty entry must have an Author |
|
282
|
|
|
//node. |
|
283
|
|
|
} else { |
|
284
|
|
|
$relativeUri = $this->getEntryInstanceKey( |
|
285
|
|
|
$entryObject, |
|
286
|
|
|
$resourceType, |
|
287
|
|
|
$this->getCurrentResourceSetWrapper()->getName() |
|
288
|
|
|
); |
|
289
|
|
|
|
|
290
|
|
|
$absoluteUri = rtrim($this->absoluteServiceUri, '/') . '/' . $relativeUri; |
|
291
|
|
|
$title = $resourceType->getName(); |
|
292
|
|
|
//TODO Resolve actual resource type |
|
293
|
|
|
$actualResourceType = $resourceType; |
|
294
|
|
|
$this->_writeMediaResourceMetadata( |
|
295
|
|
|
$entryObject, |
|
296
|
|
|
$actualResourceType, |
|
297
|
|
|
$title, |
|
298
|
|
|
$relativeUri, |
|
299
|
|
|
$entry |
|
300
|
|
|
); |
|
301
|
|
|
|
|
302
|
|
|
$entry->id = $absoluteUri; |
|
303
|
|
|
$entry->eTag = $this->getETagForEntry($entryObject, $resourceType); |
|
304
|
|
|
$entry->title = $title; |
|
305
|
|
|
$entry->editLink = $relativeUri; |
|
306
|
|
|
$entry->type = $actualResourceType->getFullName(); |
|
307
|
|
|
$odataPropertyContent = new ODataPropertyContent(); |
|
308
|
|
|
$this->_writeObjectProperties( |
|
309
|
|
|
$entryObject, |
|
310
|
|
|
$actualResourceType, |
|
311
|
|
|
$absoluteUri, |
|
312
|
|
|
$relativeUri, |
|
313
|
|
|
$entry, |
|
314
|
|
|
$odataPropertyContent |
|
315
|
|
|
); |
|
316
|
|
|
$entry->propertyContent = $odataPropertyContent; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
return $entry; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Writes the feed elements |
|
324
|
|
|
* |
|
325
|
|
|
* @param array &$entryObjects Array of entries in the feed element. |
|
326
|
|
|
* @param ResourceType &$resourceType The resource type of the f the elements |
|
327
|
|
|
* in the collection. |
|
328
|
|
|
* @param string $title Title of the feed element. |
|
329
|
|
|
* @param string $absoluteUri Absolute uri representing the feed element. |
|
330
|
|
|
* @param string $relativeUri Relative uri representing the feed element. |
|
331
|
|
|
* @param ODataFeed &$feed Feed to write to. |
|
332
|
|
|
* |
|
333
|
|
|
* @return void |
|
334
|
|
|
*/ |
|
335
|
|
|
private function _writeFeedElements( |
|
336
|
|
|
&$entryObjects, |
|
337
|
|
|
ResourceType &$resourceType, |
|
338
|
|
|
$title, |
|
339
|
|
|
$absoluteUri, |
|
340
|
|
|
$relativeUri, |
|
341
|
|
|
ODataFeed &$feed |
|
342
|
|
|
) { |
|
343
|
|
|
$this->assert(is_array($entryObjects), '_writeFeedElements::is_array($entryObjects)'); |
|
344
|
|
|
$feed->id = $absoluteUri; |
|
345
|
|
|
$feed->title = $title; |
|
346
|
|
|
$feed->selfLink = new ODataLink(); |
|
347
|
|
|
$feed->selfLink->name = ODataConstants::ATOM_SELF_RELATION_ATTRIBUTE_VALUE; |
|
348
|
|
|
$feed->selfLink->title = $title; |
|
349
|
|
|
$feed->selfLink->url = $relativeUri; |
|
350
|
|
|
|
|
351
|
|
|
if (empty($entryObjects)) { |
|
|
|
|
|
|
352
|
|
|
//TODO // ATOM specification: if a feed contains no entries, |
|
353
|
|
|
//then the feed should have at least one Author tag |
|
354
|
|
|
} else { |
|
355
|
|
|
foreach ($entryObjects as $entryObject) { |
|
356
|
|
|
$feed->entries[] = $this->_writeEntryElement($entryObject, $resourceType, null, null); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
if ($this->needNextPageLink(count($entryObjects))) { |
|
360
|
|
|
$feed->nextPageLink = $this->getNextLinkUri(end($entryObjects), $absoluteUri); |
|
|
|
|
|
|
361
|
|
|
} |
|
362
|
|
|
} |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* Write values of properties of given entry (resource) or complex object. |
|
367
|
|
|
* |
|
368
|
|
|
* @param mixed $customObject Entity or complex object |
|
369
|
|
|
* with properties |
|
370
|
|
|
* to write out. |
|
371
|
|
|
* @param ResourceType &$resourceType Resource type describing |
|
372
|
|
|
* the metadata of |
|
373
|
|
|
* the custom object. |
|
374
|
|
|
* @param string $absoluteUri Absolute uri for the given |
|
375
|
|
|
* entry object |
|
376
|
|
|
* NULL for complex object. |
|
377
|
|
|
* @param string $relativeUri Relative uri for the given |
|
378
|
|
|
* custom object. |
|
379
|
|
|
* @param ODataEntry &$odataEntry ODataEntry instance to |
|
380
|
|
|
* place links and |
|
381
|
|
|
* expansion of the |
|
382
|
|
|
* entry object, |
|
383
|
|
|
* NULL for complex object. |
|
384
|
|
|
* @param ODataPropertyContent &$odataPropertyContent ODataPropertyContent |
|
385
|
|
|
* instance in which |
|
386
|
|
|
* to place the values. |
|
387
|
|
|
* |
|
388
|
|
|
* @return void |
|
389
|
|
|
*/ |
|
390
|
|
|
private function _writeObjectProperties( |
|
391
|
|
|
$customObject, |
|
392
|
|
|
ResourceType &$resourceType, |
|
393
|
|
|
$absoluteUri, |
|
394
|
|
|
$relativeUri, |
|
395
|
|
|
&$odataEntry, |
|
396
|
|
|
ODataPropertyContent &$odataPropertyContent |
|
397
|
|
|
) { |
|
398
|
|
|
$resourceTypeKind = $resourceType->getResourceTypeKind(); |
|
399
|
|
|
if (is_null($absoluteUri) == ($resourceTypeKind == ResourceTypeKind::ENTITY) |
|
400
|
|
|
) { |
|
401
|
|
|
throw ODataException::createInternalServerError( |
|
402
|
|
|
Messages::badProviderInconsistentEntityOrComplexTypeUsage( |
|
403
|
|
|
$resourceType->getName() |
|
404
|
|
|
) |
|
405
|
|
|
); |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
$this->assert( |
|
409
|
|
|
(($resourceTypeKind == ResourceTypeKind::ENTITY) && ($odataEntry instanceof ODataEntry)) |
|
410
|
|
|
|| (($resourceTypeKind == ResourceTypeKind::COMPLEX) && is_null($odataEntry)), |
|
411
|
|
|
'(($resourceTypeKind == ResourceTypeKind::ENTITY) && ($odataEntry instanceof ODataEntry)) |
|
412
|
|
|
|| (($resourceTypeKind == ResourceTypeKind::COMPLEX) && is_null($odataEntry))' |
|
413
|
|
|
); |
|
414
|
|
|
$projectionNodes = null; |
|
415
|
|
|
$navigationProperties = null; |
|
416
|
|
|
if ($resourceTypeKind == ResourceTypeKind::ENTITY) { |
|
417
|
|
|
$projectionNodes = $this->getProjectionNodes(); |
|
418
|
|
|
$navigationProperties = array(); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
if (is_null($projectionNodes)) { |
|
422
|
|
|
//This is the code path to handle properties of Complex type |
|
423
|
|
|
//or Entry without projection (i.e. no expansion or selection) |
|
424
|
|
|
$resourceProperties = array(); |
|
|
|
|
|
|
425
|
|
|
if ($resourceTypeKind == ResourceTypeKind::ENTITY) { |
|
426
|
|
|
// If custom object is an entry then it can contain navigation |
|
427
|
|
|
// properties which are invisible (because the corresponding |
|
428
|
|
|
// resource set is invisible). |
|
429
|
|
|
// IDSMP::getResourceProperties will give collection of properties |
|
430
|
|
|
// which are visible. |
|
431
|
|
|
$currentResourceSetWrapper1 = $this->getCurrentResourceSetWrapper(); |
|
432
|
|
|
$resourceProperties = $this->service |
|
433
|
|
|
->getProvidersWrapper() |
|
434
|
|
|
->getResourceProperties( |
|
435
|
|
|
$currentResourceSetWrapper1, |
|
|
|
|
|
|
436
|
|
|
$resourceType |
|
437
|
|
|
); |
|
438
|
|
|
} else { |
|
439
|
|
|
$resourceProperties = $resourceType->getAllProperties(); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
//First write out primitve types |
|
443
|
|
|
foreach ($resourceProperties as $name => $resourceProperty) { |
|
444
|
|
|
if ($resourceProperty->getKind() == ResourcePropertyKind::PRIMITIVE |
|
445
|
|
|
|| $resourceProperty->getKind() == (ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY) |
|
446
|
|
|
|| $resourceProperty->getKind() == (ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::ETAG) |
|
447
|
|
|
|| $resourceProperty->getKind() == (ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY | ResourcePropertyKind::ETAG) |
|
448
|
|
|
) { |
|
449
|
|
|
$odataProperty = new ODataProperty(); |
|
450
|
|
|
$primitiveValue = $this->getPropertyValue($customObject, $resourceType, $resourceProperty); |
|
451
|
|
|
$this->_writePrimitiveValue($primitiveValue, $resourceProperty, $odataProperty); |
|
452
|
|
|
$odataPropertyContent->properties[] = $odataProperty; |
|
453
|
|
|
} |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
//Write out bag and complex type |
|
457
|
|
|
$i = 0; |
|
458
|
|
|
foreach ($resourceProperties as $resourceProperty) { |
|
459
|
|
|
if ($resourceProperty->isKindOf(ResourcePropertyKind::BAG)) { |
|
460
|
|
|
//Handle Bag Property (Bag of Primitive or complex) |
|
461
|
|
|
$propertyValue = $this->getPropertyValue($customObject, $resourceType, $resourceProperty); |
|
462
|
|
|
$resourceType2 = $resourceProperty->getResourceType(); |
|
463
|
|
|
$this->_writeBagValue( |
|
464
|
|
|
$propertyValue, |
|
465
|
|
|
$resourceProperty->getName(), |
|
466
|
|
|
$resourceType2, |
|
467
|
|
|
$relativeUri . '/' . $resourceProperty->getName(), |
|
468
|
|
|
$odataPropertyContent |
|
469
|
|
|
); |
|
470
|
|
|
} else { |
|
471
|
|
|
$resourcePropertyKind = $resourceProperty->getKind(); |
|
472
|
|
|
if ($resourcePropertyKind == ResourcePropertyKind::COMPLEX_TYPE) { |
|
473
|
|
|
$propertyValue = $this->getPropertyValue($customObject, $resourceType, $resourceProperty); |
|
474
|
|
|
$resourceType1 = $resourceProperty->getResourceType(); |
|
475
|
|
|
$this->_writeComplexValue( |
|
476
|
|
|
$propertyValue, |
|
477
|
|
|
$resourceProperty->getName(), |
|
478
|
|
|
$resourceType1, |
|
479
|
|
|
$relativeUri . '/' . $resourceProperty->getName(), |
|
480
|
|
|
$odataPropertyContent |
|
481
|
|
|
); |
|
482
|
|
|
} else if ($resourceProperty->getKind() == ResourcePropertyKind::PRIMITIVE |
|
483
|
|
|
|| $resourceProperty->getKind() == (ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY) |
|
484
|
|
|
|| $resourceProperty->getKind() == (ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::ETAG) |
|
485
|
|
|
|| $resourceProperty->getKind() == (ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY | ResourcePropertyKind::ETAG) |
|
486
|
|
|
) { |
|
487
|
|
|
continue; |
|
488
|
|
|
} else { |
|
489
|
|
|
$this->assert( |
|
490
|
|
|
($resourcePropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE) |
|
491
|
|
|
|| ($resourcePropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE), |
|
492
|
|
|
'($resourcePropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE) |
|
493
|
|
|
|| ($resourcePropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE)' |
|
494
|
|
|
); |
|
495
|
|
|
|
|
496
|
|
|
$navigationProperties[$i] = new NavigationPropertyInfo($resourceProperty, $this->shouldExpandSegment($resourceProperty->getName())); |
|
497
|
|
|
if ($navigationProperties[$i]->expanded) { |
|
498
|
|
|
$navigationProperties[$i]->value = $this->getPropertyValue($customObject, $resourceType, $resourceProperty); |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
$i++; |
|
502
|
|
|
} |
|
503
|
|
|
} |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
} else { //This is the code path to handle projected properties of Entry |
|
507
|
|
|
$i = 0; |
|
508
|
|
|
foreach ($projectionNodes as $projectionNode) { |
|
509
|
|
|
$propertyName = $projectionNode->getPropertyName(); |
|
510
|
|
|
$resourceProperty = $resourceType->resolveProperty($propertyName); |
|
511
|
|
|
$this->assert(!is_null($resourceProperty), '!is_null($resourceProperty)'); |
|
512
|
|
|
|
|
513
|
|
|
if ($resourceProperty->getTypeKind() == ResourceTypeKind::ENTITY) { |
|
514
|
|
|
$currentResourceSetWrapper2 = $this->getCurrentResourceSetWrapper(); |
|
515
|
|
|
$resourceProperties = $this->service |
|
516
|
|
|
->getProvidersWrapper() |
|
517
|
|
|
->getResourceProperties( |
|
518
|
|
|
$currentResourceSetWrapper2, |
|
|
|
|
|
|
519
|
|
|
$resourceType |
|
520
|
|
|
); |
|
521
|
|
|
//Check for the visibility of this navigation property |
|
522
|
|
|
if (array_key_exists($resourceProperty->getName(), $resourceProperties)) { |
|
523
|
|
|
$navigationProperties[$i] = new NavigationPropertyInfo($resourceProperty, $this->shouldExpandSegment($propertyName)); |
|
|
|
|
|
|
524
|
|
|
if ($navigationProperties[$i]->expanded) { |
|
525
|
|
|
$navigationProperties[$i]->value = $this->getPropertyValue($customObject, $resourceType, $resourceProperty); |
|
|
|
|
|
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
$i++; |
|
529
|
|
|
continue; |
|
530
|
|
|
} |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
//Primitve, complex or bag property |
|
534
|
|
|
$propertyValue = $this->getPropertyValue($customObject, $resourceType, $resourceProperty); |
|
|
|
|
|
|
535
|
|
|
$propertyTypeKind = $resourceProperty->getKind(); |
|
536
|
|
|
$propertyResourceType = $resourceProperty->getResourceType(); |
|
537
|
|
|
$this->assert(!is_null($propertyResourceType), '!is_null($propertyResourceType)'); |
|
538
|
|
|
if (ResourceProperty::sIsKindOf($propertyTypeKind, ResourcePropertyKind::BAG)) { |
|
539
|
|
|
$bagResourceType = $resourceProperty->getResourceType(); |
|
540
|
|
|
$this->_writeBagValue( |
|
541
|
|
|
$propertyValue, |
|
542
|
|
|
$propertyName, |
|
543
|
|
|
$bagResourceType, |
|
544
|
|
|
$relativeUri . '/' . $propertyName, |
|
545
|
|
|
$odataPropertyContent |
|
546
|
|
|
); |
|
547
|
|
|
} else if (ResourceProperty::sIsKindOf($propertyTypeKind, ResourcePropertyKind::PRIMITIVE)) { |
|
548
|
|
|
$odataProperty = new ODataProperty(); |
|
549
|
|
|
$this->_writePrimitiveValue($propertyValue, $resourceProperty, $odataProperty); |
|
|
|
|
|
|
550
|
|
|
$odataPropertyContent->properties[] = $odataProperty; |
|
551
|
|
|
} else if ($propertyTypeKind == ResourcePropertyKind::COMPLEX_TYPE) { |
|
552
|
|
|
$complexResourceType = $resourceProperty->getResourceType(); |
|
553
|
|
|
$this->_writeComplexValue( |
|
554
|
|
|
$propertyValue, |
|
555
|
|
|
$propertyName, |
|
556
|
|
|
$complexResourceType, |
|
557
|
|
|
$relativeUri . '/' . $propertyName, |
|
558
|
|
|
$odataPropertyContent |
|
559
|
|
|
); |
|
560
|
|
|
} else { |
|
561
|
|
|
//unexpected |
|
562
|
|
|
$this->assert(false, '$propertyTypeKind = Primitive or Bag or ComplexType'); |
|
563
|
|
|
} |
|
564
|
|
|
} |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
if (!is_null($navigationProperties)) { |
|
568
|
|
|
//Write out navigation properties (deferred or inline) |
|
569
|
|
|
foreach ($navigationProperties as $navigationPropertyInfo) { |
|
570
|
|
|
$propertyName = $navigationPropertyInfo->resourceProperty->getName(); |
|
571
|
|
|
$type = $navigationPropertyInfo->resourceProperty->getKind() == ResourcePropertyKind::RESOURCE_REFERENCE ? |
|
572
|
|
|
'application/atom+xml;type=entry': |
|
573
|
|
|
'application/atom+xml;type=feed'; |
|
574
|
|
|
$link = new ODataLink(); |
|
575
|
|
|
$link->name = ODataConstants::ODATA_RELATED_NAMESPACE . $propertyName; |
|
576
|
|
|
$link->title = $propertyName; |
|
577
|
|
|
$link->type = $type; |
|
578
|
|
|
$link->url = $relativeUri . '/' . $propertyName; |
|
579
|
|
|
|
|
580
|
|
|
if ($navigationPropertyInfo->expanded) { |
|
581
|
|
|
$propertyRelativeUri = $relativeUri . '/' . $propertyName; |
|
582
|
|
|
$propertyAbsoluteUri = trim($absoluteUri, '/') . '/' . $propertyName; |
|
583
|
|
|
$needPop = $this->pushSegmentForNavigationProperty($navigationPropertyInfo->resourceProperty); |
|
584
|
|
|
$navigationPropertyKind = $navigationPropertyInfo->resourceProperty->getKind(); |
|
585
|
|
|
$this->assert( |
|
586
|
|
|
$navigationPropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE |
|
587
|
|
|
|| $navigationPropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE, |
|
588
|
|
|
'$navigationPropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE |
|
589
|
|
|
|| $navigationPropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE' |
|
590
|
|
|
); |
|
591
|
|
|
$currentResourceSetWrapper = $this->getCurrentResourceSetWrapper(); |
|
592
|
|
|
$this->assert(!is_null($currentResourceSetWrapper), '!is_null($currentResourceSetWrapper)'); |
|
593
|
|
|
$link->isExpanded = true; |
|
594
|
|
|
if (!is_null($navigationPropertyInfo->value)) { |
|
595
|
|
|
if ($navigationPropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE) { |
|
596
|
|
|
$inlineFeed = new ODataFeed(); |
|
597
|
|
|
$link->isCollection = true; |
|
598
|
|
|
$currentResourceType = $currentResourceSetWrapper->getResourceType(); |
|
599
|
|
|
$this->_writeFeedElements( |
|
600
|
|
|
$navigationPropertyInfo->value, |
|
601
|
|
|
$currentResourceType, |
|
602
|
|
|
$propertyName, |
|
603
|
|
|
$propertyAbsoluteUri, |
|
604
|
|
|
$propertyRelativeUri, |
|
605
|
|
|
$inlineFeed |
|
606
|
|
|
); |
|
607
|
|
|
$link->expandedResult = $inlineFeed; |
|
608
|
|
|
} else { |
|
609
|
|
|
|
|
610
|
|
|
$link->isCollection = false; |
|
611
|
|
|
$currentResourceType1 = $currentResourceSetWrapper->getResourceType(); |
|
612
|
|
|
|
|
613
|
|
|
$link->expandedResult = $this->_writeEntryElement( |
|
614
|
|
|
$navigationPropertyInfo->value, |
|
615
|
|
|
$currentResourceType1, |
|
616
|
|
|
$propertyAbsoluteUri, |
|
617
|
|
|
$propertyRelativeUri |
|
618
|
|
|
); |
|
619
|
|
|
} |
|
620
|
|
|
} else { |
|
621
|
|
|
$link->expandedResult = null; |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
$this->popSegment($needPop); |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
$odataEntry->links[] = $link; |
|
628
|
|
|
} |
|
629
|
|
|
} |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* Writes a primitive value and related information to the given |
|
634
|
|
|
* ODataProperty instance. |
|
635
|
|
|
* |
|
636
|
|
|
* @param mixed &$primitiveValue The primitive value to write. |
|
637
|
|
|
* @param ResourceProperty &$resourceProperty The metadata of the primitive |
|
638
|
|
|
* property value. |
|
639
|
|
|
* @param ODataProperty &$odataProperty ODataProperty instance to which |
|
640
|
|
|
* the primitive value and related |
|
641
|
|
|
* information to write out. |
|
642
|
|
|
* |
|
643
|
|
|
* @throws ODataException If given value is not primitive. |
|
644
|
|
|
* |
|
645
|
|
|
* @return void |
|
646
|
|
|
*/ |
|
647
|
|
|
private function _writePrimitiveValue(&$primitiveValue, |
|
648
|
|
|
ResourceProperty &$resourceProperty, ODataProperty &$odataProperty |
|
649
|
|
|
) { |
|
650
|
|
|
if (is_object($primitiveValue)) { |
|
|
|
|
|
|
651
|
|
|
//TODO ERROR: The property 'PropertyName' |
|
652
|
|
|
//is defined as primitive type but value is an object |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
|
|
656
|
|
|
$odataProperty->name = $resourceProperty->getName(); |
|
657
|
|
|
$odataProperty->typeName = $resourceProperty->getInstanceType()->getFullTypeName(); |
|
|
|
|
|
|
658
|
|
|
if (is_null($primitiveValue)) { |
|
659
|
|
|
$odataProperty->value = null; |
|
660
|
|
|
} else { |
|
661
|
|
|
$resourceType = $resourceProperty->getResourceType(); |
|
662
|
|
|
$this->_primitiveToString( |
|
663
|
|
|
$resourceType, |
|
664
|
|
|
$primitiveValue, |
|
665
|
|
|
$odataProperty->value |
|
666
|
|
|
); |
|
667
|
|
|
} |
|
668
|
|
|
} |
|
669
|
|
|
|
|
670
|
|
|
/** |
|
671
|
|
|
* Write value of a complex object. |
|
672
|
|
|
* |
|
673
|
|
|
* @param mixed &$complexValue Complex object to write. |
|
674
|
|
|
* @param string $propertyName Name of the |
|
675
|
|
|
* complex property |
|
676
|
|
|
* whose value need |
|
677
|
|
|
* to be written. |
|
678
|
|
|
* @param ResourceType &$resourceType Expected type |
|
679
|
|
|
* of the property. |
|
680
|
|
|
* @param string $relativeUri Relative uri for the |
|
681
|
|
|
* complex type element. |
|
682
|
|
|
* @param ODataPropertyContent &$odataPropertyContent Content to write to. |
|
683
|
|
|
* |
|
684
|
|
|
* @return void |
|
685
|
|
|
*/ |
|
686
|
|
|
private function _writeComplexValue(&$complexValue, |
|
687
|
|
|
$propertyName, ResourceType &$resourceType, $relativeUri, |
|
688
|
|
|
ODataPropertyContent &$odataPropertyContent |
|
689
|
|
|
) { |
|
690
|
|
|
$odataProperty = new ODataProperty(); |
|
691
|
|
|
$odataProperty->name = $propertyName; |
|
692
|
|
|
if (is_null($complexValue)) { |
|
693
|
|
|
$odataProperty->value = null; |
|
694
|
|
|
$odataProperty->typeName = $resourceType->getFullName(); |
|
695
|
|
|
} else { |
|
696
|
|
|
$content = new ODataPropertyContent(); |
|
697
|
|
|
$actualType = $this->_complexObjectToContent( |
|
698
|
|
|
$complexValue, |
|
699
|
|
|
$propertyName, |
|
700
|
|
|
$resourceType, |
|
701
|
|
|
$relativeUri, |
|
702
|
|
|
$content |
|
703
|
|
|
); |
|
704
|
|
|
|
|
705
|
|
|
$odataProperty->typeName = $actualType->getFullName(); |
|
706
|
|
|
$odataProperty->value = $content; |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
$odataPropertyContent->properties[] = $odataProperty; |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
/** |
|
713
|
|
|
* Write value of a bag instance. |
|
714
|
|
|
* |
|
715
|
|
|
* @param array/NULL &$BagValue Bag value to write. |
|
716
|
|
|
* @param string $propertyName Property name of the bag. |
|
717
|
|
|
* @param ResourceType &$resourceType Type describing the |
|
718
|
|
|
* bag value. |
|
719
|
|
|
* @param string $relativeUri Relative Url to the bag. |
|
720
|
|
|
* @param ODataPropertyContent &$odataPropertyContent On return, this object |
|
721
|
|
|
* will hold bag value which |
|
722
|
|
|
* can be used by writers. |
|
723
|
|
|
* |
|
724
|
|
|
* @return void |
|
725
|
|
|
*/ |
|
726
|
|
|
private function _writeBagValue(&$BagValue, |
|
727
|
|
|
$propertyName, ResourceType &$resourceType, $relativeUri, |
|
728
|
|
|
ODataPropertyContent &$odataPropertyContent |
|
729
|
|
|
) { |
|
730
|
|
|
$bagItemResourceTypeKind = $resourceType->getResourceTypeKind(); |
|
731
|
|
|
$this->assert( |
|
732
|
|
|
$bagItemResourceTypeKind == ResourceTypeKind::PRIMITIVE |
|
733
|
|
|
|| $bagItemResourceTypeKind == ResourceTypeKind::COMPLEX, |
|
734
|
|
|
'$bagItemResourceTypeKind == ResourceTypeKind::PRIMITIVE |
|
735
|
|
|
|| $bagItemResourceTypeKind == ResourceTypeKind::COMPLEX' |
|
736
|
|
|
); |
|
737
|
|
|
|
|
738
|
|
|
$odataProperty = new ODataProperty(); |
|
739
|
|
|
$odataProperty->name = $propertyName; |
|
740
|
|
|
$odataProperty->typeName = 'Collection(' . $resourceType->getFullName() .')'; |
|
741
|
|
|
if (is_null($BagValue) || (is_array($BagValue) && empty ($BagValue))) { |
|
742
|
|
|
$odataProperty->value = null; |
|
743
|
|
|
} else { |
|
744
|
|
|
$odataBagContent = new ODataBagContent(); |
|
745
|
|
|
foreach ($BagValue as $itemValue) { |
|
746
|
|
|
if (!is_null($itemValue)) { |
|
747
|
|
|
if ($bagItemResourceTypeKind == ResourceTypeKind::PRIMITIVE) { |
|
748
|
|
|
$primitiveValueAsString = null; |
|
749
|
|
|
$this->_primitiveToString($resourceType, $itemValue, $primitiveValueAsString); |
|
750
|
|
|
$odataBagContent->propertyContents[] = $primitiveValueAsString; |
|
751
|
|
|
} else if ($bagItemResourceTypeKind == ResourceTypeKind::COMPLEX) { |
|
752
|
|
|
$complexContent = new ODataPropertyContent(); |
|
753
|
|
|
$actualType = $this->_complexObjectToContent( |
|
|
|
|
|
|
754
|
|
|
$itemValue, |
|
755
|
|
|
$propertyName, |
|
756
|
|
|
$resourceType, |
|
757
|
|
|
$relativeUri, |
|
758
|
|
|
$complexContent |
|
759
|
|
|
); |
|
760
|
|
|
//TODO add type in case of base type |
|
761
|
|
|
$odataBagContent->propertyContents[] = $complexContent; |
|
762
|
|
|
} |
|
763
|
|
|
} |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
$odataProperty->value = $odataBagContent; |
|
767
|
|
|
} |
|
768
|
|
|
|
|
769
|
|
|
$odataPropertyContent->properties[] = $odataProperty; |
|
770
|
|
|
} |
|
771
|
|
|
|
|
772
|
|
|
/** |
|
773
|
|
|
* Write media resource metadata (for MLE and Named Streams) |
|
774
|
|
|
* |
|
775
|
|
|
* @param mixed $entryObject The entry instance being serialized. |
|
776
|
|
|
* @param ResourceType &$resourceType Resource type of the entry instance. |
|
777
|
|
|
* @param string $title Title for the current |
|
778
|
|
|
* current entry instance. |
|
779
|
|
|
* @param string $relativeUri Relative uri for the |
|
780
|
|
|
* current entry instance. |
|
781
|
|
|
* @param ODataEntry &$odataEntry OData entry to write to. |
|
782
|
|
|
* |
|
783
|
|
|
* @return void |
|
784
|
|
|
*/ |
|
785
|
|
|
private function _writeMediaResourceMetadata( |
|
786
|
|
|
$entryObject, |
|
787
|
|
|
ResourceType &$resourceType, |
|
788
|
|
|
$title, |
|
789
|
|
|
$relativeUri, |
|
790
|
|
|
ODataEntry &$odataEntry |
|
791
|
|
|
) { |
|
792
|
|
|
if ($resourceType->isMediaLinkEntry()) { |
|
793
|
|
|
$odataEntry->isMediaLinkEntry = true; |
|
794
|
|
|
$streamProvider = $this->service->getStreamProvider(); |
|
|
|
|
|
|
795
|
|
|
$eTag = $streamProvider->getStreamETag($entryObject, null); |
|
796
|
|
|
$readStreamUri = $streamProvider->getReadStreamUri($entryObject, null, $relativeUri); |
|
797
|
|
|
$mediaContentType = $streamProvider->getStreamContentType($entryObject, null); |
|
798
|
|
|
$mediaLink = new ODataMediaLink( |
|
799
|
|
|
$title, |
|
800
|
|
|
$streamProvider->getDefaultStreamEditMediaUri($relativeUri, null), |
|
801
|
|
|
$readStreamUri, |
|
802
|
|
|
$mediaContentType, |
|
803
|
|
|
$eTag |
|
804
|
|
|
); |
|
805
|
|
|
|
|
806
|
|
|
$odataEntry->mediaLink = $mediaLink; |
|
807
|
|
|
} |
|
808
|
|
|
|
|
809
|
|
|
if ($resourceType->hasNamedStream()) { |
|
810
|
|
|
foreach ($resourceType->getAllNamedStreams() as $title => $resourceStreamInfo) { |
|
811
|
|
|
$eTag = $streamProvider->getStreamETag($entryObject, $resourceStreamInfo); |
|
|
|
|
|
|
812
|
|
|
$readStreamUri = $streamProvider->getReadStreamUri($entryObject, $resourceStreamInfo, $relativeUri); |
|
813
|
|
|
$mediaContentType = $streamProvider->getStreamContentType($entryObject, $resourceStreamInfo); |
|
814
|
|
|
$odataEntry->mediaLinks[] = new ODataMediaLink( |
|
815
|
|
|
$title, |
|
816
|
|
|
$streamProvider->getDefaultStreamEditMediaUri($relativeUri, $resourceStreamInfo), |
|
817
|
|
|
$readStreamUri, |
|
818
|
|
|
$mediaContentType, |
|
819
|
|
|
$eTag |
|
820
|
|
|
); |
|
821
|
|
|
} |
|
822
|
|
|
} |
|
823
|
|
|
} |
|
824
|
|
|
/** |
|
825
|
|
|
* Convert the given primitive value to string. |
|
826
|
|
|
* Note: This method will not handle null primitive value. |
|
827
|
|
|
* |
|
828
|
|
|
* @param ResourceType &$primtiveResourceType Type of the primitive property |
|
829
|
|
|
* whose value need to be converted. |
|
830
|
|
|
* @param mixed $primitiveValue Primitive value to convert. |
|
831
|
|
|
* @param string &$stringValue On return, this parameter will |
|
832
|
|
|
* contain converted value. |
|
833
|
|
|
* |
|
834
|
|
|
* @return void |
|
835
|
|
|
*/ |
|
836
|
|
|
private function _primitiveToString(ResourceType &$primtiveResourceType, |
|
837
|
|
|
$primitiveValue, &$stringValue |
|
838
|
|
|
) { |
|
839
|
|
|
$type = $primtiveResourceType->getInstanceType(); |
|
840
|
|
|
if ($type instanceof Boolean) { |
|
841
|
|
|
$stringValue = ($primitiveValue === true) ? 'true' : 'false'; |
|
842
|
|
|
} else if ($type instanceof Binary) { |
|
843
|
|
|
$stringValue = base64_encode($primitiveValue); |
|
844
|
|
|
} else if ($type instanceof DateTime && $primitiveValue instanceOf \DateTime) { |
|
845
|
|
|
$stringValue = $primitiveValue->format(\DateTime::ATOM); |
|
846
|
|
|
} else { |
|
847
|
|
|
$stringValue = strval($primitiveValue); |
|
848
|
|
|
} |
|
849
|
|
|
} |
|
850
|
|
|
|
|
851
|
|
|
/** |
|
852
|
|
|
* Write value of a complex object. |
|
853
|
|
|
* Note: This method will not handle null complex value. |
|
854
|
|
|
* |
|
855
|
|
|
* @param mixed &$complexValue Complex object to write. |
|
856
|
|
|
* @param string $propertyName Name of the |
|
857
|
|
|
* complex property |
|
858
|
|
|
* whose value |
|
859
|
|
|
* need to be written. |
|
860
|
|
|
* @param ResourceType &$resourceType Expected type of the |
|
861
|
|
|
* property. |
|
862
|
|
|
* @param string $relativeUri Relative uri for the |
|
863
|
|
|
* complex type element. |
|
864
|
|
|
* @param ODataPropertyContent &$odataPropertyContent Content to write to. |
|
865
|
|
|
* |
|
866
|
|
|
* @return ResourceType The actual type of the complex object. |
|
867
|
|
|
* |
|
868
|
|
|
* @return void |
|
869
|
|
|
*/ |
|
870
|
|
|
private function _complexObjectToContent(&$complexValue, |
|
871
|
|
|
$propertyName, ResourceType &$resourceType, $relativeUri, |
|
872
|
|
|
ODataPropertyContent &$odataPropertyContent |
|
873
|
|
|
) { |
|
874
|
|
|
$count = count($this->complexTypeInstanceCollection); |
|
875
|
|
|
for ($i = 0; $i < $count; $i++) { |
|
876
|
|
|
if ($this->complexTypeInstanceCollection[$i] === $complexValue) { |
|
877
|
|
|
throw new InvalidOperationException(Messages::objectModelSerializerLoopsNotAllowedInComplexTypes($propertyName)); |
|
878
|
|
|
} |
|
879
|
|
|
} |
|
880
|
|
|
|
|
881
|
|
|
$this->complexTypeInstanceCollection[$count] = &$complexValue; |
|
882
|
|
|
|
|
883
|
|
|
//TODO function to resolve actual type from $resourceType |
|
884
|
|
|
$actualType = $resourceType; |
|
885
|
|
|
$odataEntry = null; |
|
886
|
|
|
$this->_writeObjectProperties( |
|
887
|
|
|
$complexValue, $actualType, |
|
888
|
|
|
null, $relativeUri, $odataEntry, $odataPropertyContent |
|
889
|
|
|
); |
|
890
|
|
|
unset($this->complexTypeInstanceCollection[$count]); |
|
891
|
|
|
return $actualType; |
|
892
|
|
|
} |
|
893
|
|
|
} |
|
894
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.