1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType\EndAnonymousType; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType; |
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType; |
9
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationEndType; |
10
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationType; |
11
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypePropertyType; |
12
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypeType; |
13
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TConstraintType; |
14
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType; |
15
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType; |
16
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType; |
17
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType; |
18
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType; |
19
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType; |
20
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TReferentialConstraintRoleElementType; |
21
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTextType; |
22
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\Edmx; |
23
|
|
|
use Illuminate\Support\Str; |
24
|
|
|
use JMS\Serializer\SerializerBuilder; |
25
|
|
|
|
26
|
|
|
class MetadataManager |
27
|
|
|
{ |
28
|
|
|
private $V3Edmx = null; |
|
|
|
|
29
|
|
|
private $lastError = null; |
30
|
|
|
private $serializer = null; |
31
|
|
|
|
32
|
|
|
public function __construct($namespaceName = 'Data', $containerName = 'DefaultContainer', Edmx $edmx = null) |
33
|
|
|
{ |
34
|
|
|
$msg = null; |
35
|
|
|
$this->V3Edmx = (null == $edmx) ? new Edmx($namespaceName, $containerName) : $edmx; |
36
|
|
|
assert($this->V3Edmx->isOK($msg), $msg); |
37
|
|
|
$this->initSerialiser(); |
38
|
|
|
assert(null != $this->serializer, 'Serializer must not be null at end of constructor'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getEdmx() |
42
|
|
|
{ |
43
|
|
|
$msg = null; |
44
|
|
|
assert($this->V3Edmx->isOK($msg), $msg); |
45
|
|
|
return $this->V3Edmx; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getEdmxXML() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$cereal = $this->getSerialiser(); |
|
|
|
|
51
|
|
|
assert(null != $cereal, 'Serializer must not be null when trying to get edmx xml'); |
52
|
|
|
return $cereal->serialize($this->getEdmx(), 'xml'); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function addEntityType($name, |
56
|
|
|
TEntityTypeType $baseType = null, |
57
|
|
|
$isAbstract = false, |
58
|
|
|
$accessType = 'Public', |
59
|
|
|
$summary = null, |
60
|
|
|
$longDescription = null) |
61
|
|
|
{ |
62
|
|
|
$NewEntity = new TEntityTypeType(); |
|
|
|
|
63
|
|
|
$NewEntity->setName($name); |
|
|
|
|
64
|
|
|
$this->addDocumentation($summary, $longDescription, $NewEntity); |
|
|
|
|
65
|
|
|
$NewEntity->setAbstract($isAbstract); |
|
|
|
|
66
|
|
|
$NewEntity->setBaseType(null === $baseType ? $baseType->getName():null); |
|
|
|
|
67
|
|
|
if ($isAbstract) { |
68
|
|
|
return [$NewEntity, null]; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
$entitySet = new EntitySetAnonymousType(); |
71
|
|
|
$entitySet->setName(Str::plural($NewEntity->getName())); |
|
|
|
|
72
|
|
|
$namespace = $this->getNamespace(); |
73
|
|
|
$entityTypeName = $namespace . $NewEntity->getName(); |
|
|
|
|
74
|
|
|
$entitySet->setEntityType($entityTypeName); |
75
|
|
|
$entitySet->setGetterAccess($accessType); |
76
|
|
|
|
77
|
|
|
$this->V3Edmx->getDataServiceType()->getSchema()[0]->addToEntityType($NewEntity); |
|
|
|
|
78
|
|
|
$this->V3Edmx->getDataServiceType()->getSchema()[0]->getEntityContainer()[0]->addToEntitySet($entitySet); |
79
|
|
|
assert($this->V3Edmx->isOK($this->lastError), $this->lastError); |
80
|
|
|
return [$NewEntity, $entitySet]; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function addComplexType($name, $accessType = 'Public', $summary = null, $longDescription = null) |
84
|
|
|
{ |
85
|
|
|
$NewEntity = new TComplexTypeType(); |
|
|
|
|
86
|
|
|
$NewEntity->setName($name); |
|
|
|
|
87
|
|
|
$NewEntity->setTypeAccess($accessType); |
|
|
|
|
88
|
|
|
$this->addDocumentation($summary, $longDescription, $NewEntity); |
|
|
|
|
89
|
|
|
assert($NewEntity->isOK($this->lastError), $this->lastError); |
|
|
|
|
90
|
|
|
$this->V3Edmx->getDataServiceType()->getSchema()[0]->addToComplexType($NewEntity); |
|
|
|
|
91
|
|
|
|
92
|
|
|
return $NewEntity; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getSerialiser() |
96
|
|
|
{ |
97
|
|
|
return $this->serializer; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function addPropertyToComplexType( |
101
|
|
|
\AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypeType $complexType, |
102
|
|
|
$name, |
103
|
|
|
$type, |
104
|
|
|
$defaultValue = null, |
105
|
|
|
$nullable = false, |
106
|
|
|
$summary = null, |
107
|
|
|
$longDescription = null |
108
|
|
|
) { |
109
|
|
|
if (is_array($defaultValue) || is_object($defaultValue)) { |
110
|
|
|
throw new \InvalidArgumentException('Default value cannot be object or array'); |
111
|
|
|
} |
112
|
|
|
if (null != $defaultValue) { |
113
|
|
|
$defaultValue = var_export($defaultValue, true); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
$NewProperty = new TComplexTypePropertyType(); |
|
|
|
|
116
|
|
|
$NewProperty->setName($name); |
|
|
|
|
117
|
|
|
$NewProperty->setType($type); |
|
|
|
|
118
|
|
|
$NewProperty->setNullable($nullable); |
|
|
|
|
119
|
|
|
$this->addDocumentation($summary, $longDescription, $NewProperty); |
|
|
|
|
120
|
|
|
if (null != $defaultValue) { |
121
|
|
|
$NewProperty->setDefaultValue($defaultValue); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
assert($NewProperty->isOK($this->lastError), $this->lastError); |
|
|
|
|
124
|
|
|
$complexType->addToProperty($NewProperty); |
|
|
|
|
125
|
|
|
return $NewProperty; |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function addPropertyToEntityType( |
129
|
|
|
TEntityTypeType $entityType, |
130
|
|
|
$name, |
131
|
|
|
$type, |
132
|
|
|
$defaultValue = null, |
133
|
|
|
$nullable = false, |
134
|
|
|
$isKey = false, |
135
|
|
|
$storeGeneratedPattern = null, |
|
|
|
|
136
|
|
|
$summary = null, |
137
|
|
|
$longDescription = null |
138
|
|
|
) { |
139
|
|
|
$NewProperty = new TEntityPropertyType(); |
|
|
|
|
140
|
|
|
$NewProperty->setName($name); |
|
|
|
|
141
|
|
|
$NewProperty->setType($type); |
|
|
|
|
142
|
|
|
$NewProperty->setStoreGeneratedPattern($storeGeneratedPattern); |
|
|
|
|
143
|
|
|
$NewProperty->setNullable($nullable); |
|
|
|
|
144
|
|
|
$this->addDocumentation($summary, $longDescription, $NewProperty); |
|
|
|
|
145
|
|
|
if (null != $defaultValue) { |
146
|
|
|
$NewProperty->setDefaultValue($defaultValue); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
$entityType->addToProperty($NewProperty); |
|
|
|
|
149
|
|
|
if ($isKey) { |
150
|
|
|
$Key = new TPropertyRefType(); |
|
|
|
|
151
|
|
|
$Key->setName($name); |
|
|
|
|
152
|
|
|
$entityType->addToKey($Key); |
|
|
|
|
153
|
|
|
} |
154
|
|
|
return $NewProperty; |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function addNavigationPropertyToEntityType( |
158
|
|
|
TEntityTypeType $principalType, |
159
|
|
|
$principalMultiplicity, |
|
|
|
|
160
|
|
|
$principalProperty, |
161
|
|
|
TEntityTypeType $dependentType, |
162
|
|
|
$dependentMultiplicity, |
|
|
|
|
163
|
|
|
$dependentProperty = '', |
164
|
|
|
array $principalConstraintProperty = null, |
|
|
|
|
165
|
|
|
array $dependentConstraintProperty = null, |
|
|
|
|
166
|
|
|
$principalGetterAccess = 'Public', |
|
|
|
|
167
|
|
|
$principalSetterAccess = 'Public', |
|
|
|
|
168
|
|
|
$dependentGetterAccess = 'Public', |
|
|
|
|
169
|
|
|
$dependentSetterAccess = 'Public', |
|
|
|
|
170
|
|
|
$principalSummery = null, |
171
|
|
|
$principalLongDescription = null, |
|
|
|
|
172
|
|
|
$dependentSummery = null, |
173
|
|
|
$dependentLongDescription = null |
|
|
|
|
174
|
|
|
) { |
175
|
|
|
$principalEntitySetName = Str::plural($principalType->getName()); |
|
|
|
|
176
|
|
|
$dependentEntitySetName = Str::plural($dependentType->getName()); |
|
|
|
|
177
|
|
|
$relationName = $principalType->getName() . '_' . $principalProperty . '_' |
178
|
|
|
. $dependentType->getName() . '_' . $dependentProperty; |
179
|
|
|
$relationName = trim($relationName, '_'); |
180
|
|
|
|
181
|
|
|
$namespace = $this->getNamespace(); |
182
|
|
|
$relationFQName = $namespace . $relationName; |
183
|
|
|
|
184
|
|
|
$principalNavigationProperty = new TNavigationPropertyType(); |
|
|
|
|
185
|
|
|
$principalNavigationProperty->setName($principalProperty); |
186
|
|
|
$principalNavigationProperty->setToRole(trim($dependentEntitySetName . '_' . $dependentProperty, '_')); |
187
|
|
|
$principalNavigationProperty->setFromRole($principalEntitySetName . '_' . $principalProperty); |
188
|
|
|
$principalNavigationProperty->setRelationship($relationFQName); |
189
|
|
|
$principalNavigationProperty->setGetterAccess($principalGetterAccess); |
190
|
|
|
$principalNavigationProperty->setSetterAccess($principalSetterAccess); |
191
|
|
|
$this->addDocumentation($principalSummery, $principalLongDescription, $principalNavigationProperty); |
192
|
|
|
$principalType->addToNavigationProperty($principalNavigationProperty); |
|
|
|
|
193
|
|
|
$dependentNavigationProperty = null; |
|
|
|
|
194
|
|
|
if (!empty($dependentProperty)) { |
195
|
|
|
$dependentNavigationProperty = new TNavigationPropertyType(); |
196
|
|
|
$dependentNavigationProperty->setName($dependentProperty); |
197
|
|
|
$dependentNavigationProperty->setToRole($principalEntitySetName . '_' . $principalProperty); |
198
|
|
|
$dependentNavigationProperty->setFromRole($dependentEntitySetName . '_' . $dependentProperty); |
199
|
|
|
$dependentNavigationProperty->setRelationship($relationFQName); |
200
|
|
|
$dependentNavigationProperty->setGetterAccess($dependentGetterAccess); |
201
|
|
|
$dependentNavigationProperty->setSetterAccess($dependentSetterAccess); |
202
|
|
|
$this->addDocumentation($dependentSummery, $dependentLongDescription, $dependentNavigationProperty); |
203
|
|
|
$dependentType->addToNavigationProperty($dependentNavigationProperty); |
|
|
|
|
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
$assocation = $this->createAssocationFromNavigationProperty( |
207
|
|
|
$principalType, |
208
|
|
|
$dependentType, |
209
|
|
|
$principalNavigationProperty, |
|
|
|
|
210
|
|
|
$dependentNavigationProperty, |
|
|
|
|
211
|
|
|
$principalMultiplicity, |
212
|
|
|
$dependentMultiplicity, |
213
|
|
|
$principalConstraintProperty, |
214
|
|
|
$dependentConstraintProperty |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$this->V3Edmx->getDataServiceType()->getSchema()[0]->addToAssociation($assocation); |
218
|
|
|
|
219
|
|
|
$associationSet = $this->createAssocationSetForAssocation( |
220
|
|
|
$assocation, |
221
|
|
|
$principalEntitySetName, |
222
|
|
|
$dependentEntitySetName |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$this->V3Edmx->getDataServiceType()->getSchema()[0] |
226
|
|
|
->getEntityContainer()[0]->addToAssociationSet($associationSet); |
227
|
|
|
|
228
|
|
|
assert($this->V3Edmx->isOK($this->lastError), $this->lastError); |
229
|
|
|
return [$principalNavigationProperty, $dependentNavigationProperty]; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
protected function createAssocationFromNavigationProperty( |
233
|
|
|
TEntityTypeType $principalType, |
234
|
|
|
TEntityTypeType $dependentType, |
235
|
|
|
TNavigationPropertyType $principalNavigationProperty, |
|
|
|
|
236
|
|
|
TNavigationPropertyType $dependentNavigationProperty = null, |
|
|
|
|
237
|
|
|
$principalMultiplicity, |
|
|
|
|
238
|
|
|
$dependentMultiplicity, |
|
|
|
|
239
|
|
|
array $principalConstraintProperty = null, |
|
|
|
|
240
|
|
|
array $dependentConstraintProperty = null |
|
|
|
|
241
|
|
|
) { |
242
|
|
|
$multCombo = ['*' => ['*', '1'], '0..1' => ['1'], '1' => ['*', '0..1']]; |
243
|
|
|
$multKeys = array_keys($multCombo); |
244
|
|
|
if (null != $dependentNavigationProperty) { |
245
|
|
|
if ($dependentNavigationProperty->getRelationship() != $principalNavigationProperty->getRelationship()) { |
246
|
|
|
$msg = 'If you have both a dependent property and a principal property,' |
247
|
|
|
.' relationship should match'; |
248
|
|
|
throw new \InvalidArgumentException($msg); |
249
|
|
|
} |
250
|
|
|
if ($dependentNavigationProperty->getFromRole() != $principalNavigationProperty->getToRole() |
251
|
|
|
|| $dependentNavigationProperty->getToRole() != $principalNavigationProperty->getFromRole() |
252
|
|
|
) { |
253
|
|
|
throw new \InvalidArgumentException( |
254
|
|
|
'Principal to role should match dependent from role, and vice versa' |
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
if (!in_array($principalMultiplicity, $multKeys) || !in_array($dependentMultiplicity, $multKeys)) { |
259
|
|
|
throw new \InvalidArgumentException('Malformed multiplicity - valid values are *, 0..1 and 1'); |
260
|
|
|
} |
261
|
|
|
if (!in_array($dependentMultiplicity, $multCombo[$principalMultiplicity])) { |
262
|
|
|
throw new \InvalidArgumentException( |
263
|
|
|
'Invalid multiplicity combination - ' . $principalMultiplicity . ' ' . $dependentMultiplicity |
264
|
|
|
); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
$namespace = $this->getNamespace(); |
268
|
|
|
$principalTypeFQName = $namespace . $principalType->getName(); |
269
|
|
|
$dependentTypeFQName = $namespace . $dependentType->getName(); |
270
|
|
|
$association = new TAssociationType(); |
271
|
|
|
$relationship = $principalNavigationProperty->getRelationship(); |
272
|
|
|
if (false !== strpos($relationship, '.')) { |
273
|
|
|
$relationship = substr($relationship, strpos($relationship, '.') + 1); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
$principalTargRole = $principalNavigationProperty->getFromRole(); |
277
|
|
|
$principalSrcRole = $principalNavigationProperty->getToRole(); |
278
|
|
|
$dependentTargRole = null != $dependentNavigationProperty ? $dependentNavigationProperty->getFromRole() : null; |
279
|
|
|
|
280
|
|
|
$association->setName($relationship); |
281
|
|
|
$principalEnd = new TAssociationEndType(); |
282
|
|
|
$principalEnd->setType($principalTypeFQName); |
283
|
|
|
$principalEnd->setRole($principalTargRole); |
284
|
|
|
$principalEnd->setMultiplicity($principalMultiplicity); |
285
|
|
|
$association->addToEnd($principalEnd); |
286
|
|
|
$dependentEnd = new TAssociationEndType(); |
287
|
|
|
$dependentEnd->setType($dependentTypeFQName); |
288
|
|
|
$dependentEnd->setMultiplicity($dependentMultiplicity); |
289
|
|
|
$association->addToEnd($dependentEnd); |
290
|
|
|
|
291
|
|
|
$dependentEnd->setRole(null != $dependentNavigationProperty ? $dependentTargRole : $principalSrcRole); |
292
|
|
|
|
293
|
|
|
$hasPrincipalReferral = null != $principalConstraintProperty && 0 < count($principalConstraintProperty); |
294
|
|
|
$hasDependentReferral = null != $dependentConstraintProperty && 0 < count($dependentConstraintProperty); |
295
|
|
|
|
296
|
|
|
if ($hasPrincipalReferral && $hasDependentReferral) { |
297
|
|
|
$principalReferralConstraint = $this->makeReferentialConstraint( |
|
|
|
|
298
|
|
|
$principalConstraintProperty, $principalTargRole |
299
|
|
|
); |
300
|
|
|
$dependentReferralConstraint = $this->makeReferentialConstraint( |
|
|
|
|
301
|
|
|
$dependentConstraintProperty, $dependentTargRole |
302
|
|
|
); |
303
|
|
|
$constraint = new TConstraintType(); |
304
|
|
|
$constraint->setPrincipal($principalReferralConstraint); |
305
|
|
|
$constraint->setDependent($dependentReferralConstraint); |
306
|
|
|
$association->setReferentialConstraint($constraint); |
307
|
|
|
} |
308
|
|
|
return $association; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param string $principalEntitySetName |
313
|
|
|
* @param string $dependentEntitySetName |
314
|
|
|
*/ |
315
|
|
|
protected function createAssocationSetForAssocation( |
316
|
|
|
TAssociationType $association, |
317
|
|
|
$principalEntitySetName, |
|
|
|
|
318
|
|
|
$dependentEntitySetName |
|
|
|
|
319
|
|
|
) { |
320
|
|
|
$as = new AssociationSetAnonymousType(); |
|
|
|
|
321
|
|
|
$name = $association->getName(); |
322
|
|
|
$as->setName($name); |
323
|
|
|
$namespace = $this->getNamespace(); |
324
|
|
|
$associationSetName = $namespace . $association->getName(); |
325
|
|
|
$as->setAssociation($associationSetName); |
326
|
|
|
$end1 = new EndAnonymousType(); |
327
|
|
|
$end1->setRole($association->getEnd()[0]->getRole()); |
328
|
|
|
$end1->setEntitySet($principalEntitySetName); |
329
|
|
|
$end2 = new EndAnonymousType(); |
330
|
|
|
$end2->setRole($association->getEnd()[1]->getRole()); |
331
|
|
|
$end2->setEntitySet($dependentEntitySetName); |
332
|
|
|
assert($end1->getRole() != $end2->getRole()); |
333
|
|
|
$as->addToEnd($end1); |
334
|
|
|
$as->addToEnd($end2); |
335
|
|
|
return $as; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
public function getLastError() |
|
|
|
|
339
|
|
|
{ |
340
|
|
|
return $this->lastError; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @param string $name |
345
|
|
|
* @param IsOK $expectedReturnType |
346
|
|
|
* @param TTextType $shortDesc |
|
|
|
|
347
|
|
|
* @param TTextType $longDesc |
|
|
|
|
348
|
|
|
* @return FunctionImportAnonymousType |
349
|
|
|
*/ |
350
|
|
|
public function createSingleton( |
351
|
|
|
$name, |
352
|
|
|
IsOK $expectedReturnType, |
353
|
|
|
TTextType $shortDesc = null, |
354
|
|
|
TTextType $longDesc = null |
355
|
|
|
) { |
356
|
|
|
if (!($expectedReturnType instanceof TEntityTypeType) && !($expectedReturnType instanceof TComplexTypeType)) { |
357
|
|
|
$msg = 'Expected return type must be either TEntityType or TComplexType'; |
358
|
|
|
throw new \InvalidArgumentException($msg); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
if (!is_string($name) || empty($name)) { |
362
|
|
|
$msg = 'Name must be a non-empty string'; |
363
|
|
|
throw new \InvalidArgumentException($msg); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
$funcType = new FunctionImportAnonymousType(); |
367
|
|
|
$funcType->setName($name); |
368
|
|
|
|
369
|
|
|
$typeName = $expectedReturnType->getName(); |
370
|
|
|
$returnType = new TFunctionImportReturnTypeType(); |
371
|
|
|
$returnType->setType($typeName); |
372
|
|
|
$returnType->setEntitySetAttribute($typeName); |
373
|
|
|
assert($returnType->isOK($msg), $msg); |
374
|
|
|
$funcType->addToReturnType($returnType); |
375
|
|
|
$this->addDocumentation($shortDesc, $longDesc, $funcType); |
376
|
|
|
|
377
|
|
|
$this->getEdmx()->getDataServiceType()->getSchema()[0]->getEntityContainer()[0]->addToFunctionImport($funcType); |
|
|
|
|
378
|
|
|
|
379
|
|
|
return $funcType; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
private function initSerialiser() |
383
|
|
|
{ |
384
|
|
|
$ymlDir = __DIR__ . DIRECTORY_SEPARATOR . 'MetadataV3' . DIRECTORY_SEPARATOR . 'JMSmetadata'; |
385
|
|
|
$this->serializer = |
386
|
|
|
SerializerBuilder::create() |
387
|
|
|
->addMetadataDir($ymlDir) |
388
|
|
|
->build(); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
public function __sleep() |
392
|
|
|
{ |
393
|
|
|
$this->serializer = null; |
394
|
|
|
$result = array_keys(get_object_vars($this)); |
395
|
|
|
return $result; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
public function __wakeup() |
399
|
|
|
{ |
400
|
|
|
$this->initSerialiser(); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @param $summary |
405
|
|
|
* @param $longDescription |
406
|
|
|
* @return TDocumentationType |
407
|
|
|
*/ |
408
|
|
|
private function generateDocumentation(TTextType $summary, TTextType $longDescription) |
409
|
|
|
{ |
410
|
|
|
$documentation = new TDocumentationType(); |
411
|
|
|
$documentation->setSummary($summary); |
412
|
|
|
$documentation->setLongDescription($longDescription); |
413
|
|
|
return $documentation; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @return string |
418
|
|
|
*/ |
419
|
|
|
private function getNamespace() |
420
|
|
|
{ |
421
|
|
|
$namespace = $this->V3Edmx->getDataServiceType()->getSchema()[0]->getNamespace(); |
422
|
|
|
if (0 == strlen(trim($namespace))) { |
423
|
|
|
$namespace = ''; |
424
|
|
|
} else { |
425
|
|
|
$namespace .= '.'; |
426
|
|
|
} |
427
|
|
|
return $namespace; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @param array $constraintProperty |
432
|
|
|
* @param string $targRole |
433
|
|
|
* @return TReferentialConstraintRoleElementType |
434
|
|
|
*/ |
435
|
|
|
protected function makeReferentialConstraint(array $constraintProperty, $targRole) |
436
|
|
|
{ |
437
|
|
|
assert(!empty($constraintProperty)); |
438
|
|
|
assert(is_string($targRole)); |
439
|
|
|
$referralConstraint = new TReferentialConstraintRoleElementType(); |
440
|
|
|
$referralConstraint->setRole($targRole); |
441
|
|
|
foreach ($constraintProperty as $propertyRef) { |
442
|
|
|
$TpropertyRef = new TPropertyRefType(); |
|
|
|
|
443
|
|
|
$TpropertyRef->setName($propertyRef); |
|
|
|
|
444
|
|
|
$referralConstraint->addToPropertyRef($TpropertyRef); |
|
|
|
|
445
|
|
|
} |
446
|
|
|
return $referralConstraint; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* @param $summary |
451
|
|
|
* @param $longDescription |
452
|
|
|
* @param $NewEntity |
453
|
|
|
*/ |
454
|
|
|
private function addDocumentation($summary, $longDescription, IsOK & $NewEntity) |
|
|
|
|
455
|
|
|
{ |
456
|
|
|
if (null != $summary && null != $longDescription) { |
457
|
|
|
$documentation = $this->generateDocumentation($summary, $longDescription); |
458
|
|
|
if (method_exists($NewEntity, 'addToDocumentation')) { |
|
|
|
|
459
|
|
|
$NewEntity->addToDocumentation($documentation); |
|
|
|
|
460
|
|
|
} else { |
461
|
|
|
$NewEntity->setDocumentation($documentation); |
|
|
|
|
462
|
|
|
} |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.