1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\File; |
4
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Container\PhpElement\Method; |
6
|
|
|
use WsdlToPhp\PackageGenerator\Container\PhpElement\Property; |
7
|
|
|
use WsdlToPhp\PackageGenerator\Container\PhpElement\Constant; |
8
|
|
|
use WsdlToPhp\PackageGenerator\Model\Struct as StructModel; |
9
|
|
|
use WsdlToPhp\PackageGenerator\Model\StructAttribute as StructAttributeModel; |
10
|
|
|
use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
11
|
|
|
use WsdlToPhp\PackageGenerator\File\Utils as FileUtils; |
12
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Utils as GeneratorUtils; |
13
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock; |
14
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpAnnotation; |
15
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpMethod; |
16
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpProperty; |
17
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpConstant; |
18
|
|
|
use WsdlToPhp\PhpGenerator\Component\PhpClass; |
19
|
|
|
use WsdlToPhp\PackageGenerator\ConfigurationReader\XsdTypes; |
20
|
|
|
|
21
|
|
|
abstract class AbstractModelFile extends AbstractFile |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Long annotation string |
25
|
|
|
*/ |
26
|
|
|
const ANNOTATION_LONG_LENGTH = '250'; |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
const ANNOTATION_PACKAGE = 'package'; |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
const ANNOTATION_SUB_PACKAGE = 'subpackage'; |
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
const ANNOTATION_RETURN = 'return'; |
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
const ANNOTATION_USES = 'uses'; |
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
const ANNOTATION_PARAM = 'param'; |
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
const ANNOTATION_VAR = 'var'; |
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
const ANNOTATION_SEE = 'see'; |
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
const ANNOTATION_THROWS = 'throws'; |
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
const METHOD_CONSTRUCT = '__construct'; |
63
|
|
|
/** |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
const METHOD_SET_STATE = '__set_state'; |
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
const TYPE_STRING = 'string'; |
71
|
|
|
/** |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
const TYPE_ARRAY = 'array'; |
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
const SRC_FOLDER = 'src/'; |
79
|
|
|
/** |
80
|
|
|
* @var AbstractModel |
81
|
|
|
*/ |
82
|
|
|
protected $model; |
83
|
|
|
/** |
84
|
|
|
* @param bool $withSrc |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
192 |
|
public function getFileDestination($withSrc = true) |
88
|
|
|
{ |
89
|
192 |
|
return sprintf('%s%s%s', $this->getDestinationFolder($withSrc), $this->getModel()->getSubDirectory(), $this->getModel()->getSubDirectory() !== '' ? '/' : ''); |
90
|
|
|
} |
91
|
|
|
/** |
92
|
|
|
* @param bool $withSrc |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
192 |
|
public function getDestinationFolder($withSrc = true) |
96
|
|
|
{ |
97
|
192 |
|
return sprintf('%s%s', $this->getGenerator()->getOptionDestination(), $withSrc === true ? self::SRC_FOLDER : ''); |
98
|
|
|
} |
99
|
|
|
/** |
100
|
|
|
* @see \WsdlToPhp\PackageGenerator\File\AbstractFile::writeFile() |
101
|
|
|
* @param bool $withSrc |
102
|
|
|
* @return int|bool |
103
|
|
|
*/ |
104
|
172 |
|
public function writeFile($withSrc = true) |
105
|
|
|
{ |
106
|
172 |
|
if (!$this->getModel() instanceof AbstractModel) { |
107
|
4 |
|
throw new \InvalidArgumentException('You MUST define the model before begin able to generate the file', __LINE__); |
108
|
|
|
} |
109
|
168 |
|
GeneratorUtils::createDirectory($this->getFileDestination($withSrc)); |
110
|
126 |
|
$this |
111
|
168 |
|
->defineNamespace() |
112
|
168 |
|
->defineUseStatement() |
113
|
168 |
|
->addAnnotationBlock() |
114
|
168 |
|
->addClassElement(); |
115
|
168 |
|
return parent::writeFile(); |
116
|
|
|
} |
117
|
|
|
/** |
118
|
|
|
* @return AbstractModelFile |
119
|
|
|
*/ |
120
|
168 |
|
protected function addAnnotationBlock() |
121
|
|
|
{ |
122
|
126 |
|
$this |
123
|
168 |
|
->getFile() |
124
|
168 |
|
->addAnnotationBlockElement($this->getClassAnnotationBlock()); |
125
|
168 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
/** |
128
|
|
|
* @param AbstractModel $model |
129
|
|
|
* @return AbstractModelFile |
130
|
|
|
*/ |
131
|
216 |
|
public function setModel(AbstractModel $model) |
132
|
|
|
{ |
133
|
216 |
|
$this->model = $model; |
134
|
216 |
|
$this->getFile()->getMainElement()->setName($model->getPackagedName()); |
135
|
216 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
/** |
138
|
|
|
* @return AbstractModel |
139
|
|
|
*/ |
140
|
220 |
|
public function getModel() |
141
|
|
|
{ |
142
|
220 |
|
return $this->model; |
143
|
|
|
} |
144
|
|
|
/** |
145
|
|
|
* @param string $name |
146
|
|
|
* @return StructModel|null |
147
|
|
|
*/ |
148
|
16 |
|
protected function getModelByName($name) |
149
|
|
|
{ |
150
|
16 |
|
return $this->getGenerator()->getStruct($name); |
151
|
|
|
} |
152
|
|
|
/** |
153
|
|
|
* @param PhpAnnotationBlock $block |
154
|
|
|
* @return AbstractModelFile |
155
|
|
|
*/ |
156
|
156 |
|
protected function definePackageAnnotations(PhpAnnotationBlock $block) |
157
|
|
|
{ |
158
|
156 |
|
$packageName = $this->getPackageName(); |
159
|
156 |
|
if (!empty($packageName)) { |
160
|
136 |
|
$block->addChild(new PhpAnnotation(self::ANNOTATION_PACKAGE, $packageName)); |
161
|
102 |
|
} |
162
|
156 |
|
if (count($this->getModel()->getDocSubPackages()) > 0) { |
163
|
156 |
|
$block->addChild(new PhpAnnotation(self::ANNOTATION_SUB_PACKAGE, implode(',', $this->getModel()->getDocSubPackages()))); |
164
|
117 |
|
} |
165
|
156 |
|
return $this; |
166
|
|
|
} |
167
|
|
|
/** |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
156 |
|
protected function getPackageName() |
171
|
|
|
{ |
172
|
156 |
|
$packageName = ''; |
173
|
156 |
|
if ($this->getGenerator()->getOptionPrefix() !== '') { |
174
|
128 |
|
$packageName = $this->getGenerator()->getOptionPrefix(); |
175
|
124 |
|
} elseif ($this->getGenerator()->getOptionSuffix() !== '') { |
176
|
8 |
|
$packageName = $this->getGenerator()->getOptionSuffix(); |
177
|
6 |
|
} |
178
|
156 |
|
return $packageName; |
179
|
|
|
} |
180
|
|
|
/** |
181
|
|
|
* @param PhpAnnotationBlock $block |
182
|
|
|
* @return AbstractModelFile |
183
|
|
|
*/ |
184
|
156 |
|
protected function defineGeneralAnnotations(PhpAnnotationBlock $block) |
185
|
|
|
{ |
186
|
156 |
|
foreach ($this->getGenerator()->getOptionAddComments() as $tagName => $tagValue) { |
187
|
136 |
|
$block->addChild(new PhpAnnotation($tagName, $tagValue)); |
188
|
117 |
|
} |
189
|
156 |
|
return $this; |
190
|
|
|
} |
191
|
|
|
/** |
192
|
|
|
* @return PhpAnnotationBlock |
193
|
|
|
*/ |
194
|
156 |
|
protected function getClassAnnotationBlock() |
195
|
|
|
{ |
196
|
156 |
|
$block = new PhpAnnotationBlock(); |
197
|
156 |
|
$block->addChild($this->getClassDeclarationLine()); |
198
|
117 |
|
$this |
199
|
156 |
|
->defineModelAnnotationsFromWsdl($block) |
200
|
156 |
|
->definePackageAnnotations($block) |
201
|
156 |
|
->defineGeneralAnnotations($block); |
202
|
156 |
|
return $block; |
203
|
|
|
} |
204
|
|
|
/** |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
156 |
|
protected function getClassDeclarationLine() |
208
|
|
|
{ |
209
|
156 |
|
return sprintf($this->getClassDeclarationLineText(), $this->getModel()->getName(), $this->getModel()->getContextualPart()); |
210
|
|
|
} |
211
|
|
|
/** |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
140 |
|
protected function getClassDeclarationLineText() |
215
|
|
|
{ |
216
|
140 |
|
return 'This class stands for %s %s'; |
217
|
|
|
} |
218
|
|
|
/** |
219
|
|
|
* @param PhpAnnotationBlock $block |
220
|
|
|
* @param AbstractModel $model |
221
|
|
|
* @return AbstractModelFile |
222
|
|
|
*/ |
223
|
156 |
|
protected function defineModelAnnotationsFromWsdl(PhpAnnotationBlock $block, AbstractModel $model = null) |
224
|
|
|
{ |
225
|
156 |
|
FileUtils::defineModelAnnotationsFromWsdl($block, $model instanceof AbstractModel ? $model : $this->getModel()); |
226
|
156 |
|
return $this; |
227
|
|
|
} |
228
|
|
|
/** |
229
|
|
|
* @param AbstractModel $model |
230
|
|
|
* @return string[] |
231
|
|
|
*/ |
232
|
|
|
protected function getValidMetaValues(AbstractModel $model) |
233
|
|
|
{ |
234
|
|
|
return FileUtils::getValidMetaValues($model); |
235
|
|
|
} |
236
|
|
|
/** |
237
|
|
|
* @return AbstractModelFile |
238
|
|
|
*/ |
239
|
168 |
|
protected function addClassElement() |
240
|
|
|
{ |
241
|
168 |
|
$class = new PhpClass($this->getModel()->getPackagedName(), $this->getModel()->getIsAbstract(), $this->getModel()->getExtendsClassName() === '' ? null : $this->getModel()->getExtendsClassName()); |
242
|
126 |
|
$this |
243
|
168 |
|
->defineConstants($class) |
244
|
168 |
|
->defineProperties($class) |
245
|
168 |
|
->defineMethods($class) |
246
|
168 |
|
->defineStringMethod($class) |
247
|
168 |
|
->getFile() |
248
|
168 |
|
->addClassComponent($class); |
249
|
168 |
|
return $this; |
250
|
|
|
} |
251
|
|
|
/** |
252
|
|
|
* @return AbstractModelFile |
253
|
|
|
*/ |
254
|
168 |
|
protected function defineNamespace() |
255
|
|
|
{ |
256
|
168 |
|
if ($this->getModel()->getNamespace() !== '') { |
257
|
126 |
|
$this |
258
|
168 |
|
->getFile() |
259
|
168 |
|
->setNamespace($this->getModel()->getNamespace()); |
260
|
126 |
|
} |
261
|
168 |
|
return $this; |
262
|
|
|
} |
263
|
|
|
/** |
264
|
|
|
* @return AbstractModelFile |
265
|
|
|
*/ |
266
|
168 |
|
protected function defineUseStatement() |
267
|
|
|
{ |
268
|
168 |
|
if ($this->getModel()->getExtends() !== '') { |
269
|
96 |
|
$this |
270
|
128 |
|
->getFile() |
271
|
128 |
|
->addUse($this->getModel()->getExtends(), null, true); |
272
|
96 |
|
} |
273
|
168 |
|
return $this; |
274
|
|
|
} |
275
|
|
|
/** |
276
|
|
|
* @param PhpClass $class |
277
|
|
|
* @return AbstractModelFile |
278
|
|
|
*/ |
279
|
168 |
|
protected function defineConstants(PhpClass $class) |
280
|
|
|
{ |
281
|
168 |
|
$constants = new Constant($this->getGenerator()); |
282
|
168 |
|
$this->getClassConstants($constants); |
283
|
168 |
|
foreach ($constants as $constant) { |
284
|
48 |
|
$annotationBlock = $this->getConstantAnnotationBlock($constant); |
285
|
48 |
|
if (!empty($annotationBlock)) { |
286
|
48 |
|
$class->addAnnotationBlockElement($annotationBlock); |
287
|
36 |
|
} |
288
|
48 |
|
$class->addConstantElement($constant); |
289
|
126 |
|
} |
290
|
168 |
|
return $this; |
291
|
|
|
} |
292
|
|
|
/** |
293
|
|
|
* @param PhpClass $class |
294
|
|
|
* @return AbstractModelFile |
295
|
|
|
*/ |
296
|
168 |
|
protected function defineProperties(PhpClass $class) |
297
|
|
|
{ |
298
|
168 |
|
$properties = new Property($this->getGenerator()); |
299
|
168 |
|
$this->getClassProperties($properties); |
300
|
168 |
|
foreach ($properties as $property) { |
301
|
76 |
|
$annotationBlock = $this->getPropertyAnnotationBlock($property); |
302
|
76 |
|
if (!empty($annotationBlock)) { |
303
|
76 |
|
$class->addAnnotationBlockElement($annotationBlock); |
304
|
57 |
|
} |
305
|
76 |
|
$class->addPropertyElement($property); |
306
|
126 |
|
} |
307
|
168 |
|
return $this; |
308
|
|
|
} |
309
|
|
|
/** |
310
|
|
|
* @param PhpClass $class |
311
|
|
|
* @return AbstractModelFile |
312
|
|
|
*/ |
313
|
168 |
|
protected function defineMethods(PhpClass $class) |
314
|
|
|
{ |
315
|
168 |
|
$methods = new Method($this->getGenerator()); |
316
|
168 |
|
$this->getClassMethods($methods); |
317
|
168 |
|
foreach ($methods as $method) { |
318
|
168 |
|
$annotationBlock = $this->getMethodAnnotationBlock($method); |
319
|
168 |
|
if (!empty($annotationBlock)) { |
320
|
168 |
|
$class->addAnnotationBlockElement($annotationBlock); |
321
|
126 |
|
} |
322
|
168 |
|
$class->addMethodElement($method); |
323
|
126 |
|
} |
324
|
168 |
|
return $this; |
325
|
|
|
} |
326
|
|
|
/** |
327
|
|
|
* @param Constant $constants |
328
|
|
|
*/ |
329
|
|
|
abstract protected function getClassConstants(Constant $constants); |
330
|
|
|
/** |
331
|
|
|
* @param PhpConstant $constant |
332
|
|
|
* @return PhpAnnotationBlock|null |
333
|
|
|
*/ |
334
|
|
|
abstract protected function getConstantAnnotationBlock(PhpConstant $constant); |
335
|
|
|
/** |
336
|
|
|
* @param Property $properties |
337
|
|
|
*/ |
338
|
|
|
abstract protected function getClassProperties(Property $properties); |
339
|
|
|
/** |
340
|
|
|
* @param PhpProperty $property |
341
|
|
|
* @return PhpAnnotationBlock|null |
342
|
|
|
*/ |
343
|
|
|
abstract protected function getPropertyAnnotationBlock(PhpProperty $property); |
344
|
|
|
/** |
345
|
|
|
* @param Method $methods |
346
|
|
|
*/ |
347
|
|
|
abstract protected function getClassMethods(Method $methods); |
348
|
|
|
/** |
349
|
|
|
* @param PhpMethod $method |
350
|
|
|
* @return PhpAnnotationBlock|null |
351
|
|
|
*/ |
352
|
|
|
abstract protected function getMethodAnnotationBlock(PhpMethod $method); |
353
|
|
|
/** |
354
|
|
|
* @param PhpClass $class |
355
|
|
|
*/ |
356
|
156 |
|
protected function defineStringMethod(PhpClass $class) |
357
|
|
|
{ |
358
|
156 |
|
$class->addAnnotationBlockElement($this->getToStringMethodAnnotationBlock()); |
359
|
156 |
|
$class->addMethodElement($this->getToStringMethod()); |
360
|
156 |
|
return $this; |
361
|
|
|
} |
362
|
|
|
/** |
363
|
|
|
* @return PhpAnnotationBlock |
364
|
|
|
*/ |
365
|
156 |
|
protected function getToStringMethodAnnotationBlock() |
366
|
|
|
{ |
367
|
156 |
|
return new PhpAnnotationBlock(array( |
368
|
156 |
|
'Method returning the class name', |
369
|
156 |
|
new PhpAnnotation(self::ANNOTATION_RETURN, 'string __CLASS__'), |
370
|
117 |
|
)); |
371
|
|
|
} |
372
|
|
|
/** |
373
|
|
|
* @return PhpMethod |
374
|
|
|
*/ |
375
|
156 |
|
protected function getToStringMethod() |
376
|
|
|
{ |
377
|
156 |
|
$method = new PhpMethod('__toString'); |
378
|
156 |
|
$method->addChild('return __CLASS__;'); |
379
|
156 |
|
return $method; |
380
|
|
|
} |
381
|
|
|
/** |
382
|
|
|
* @param StructAttributeModel $attribute |
383
|
|
|
* @return StructAttributeModel |
384
|
|
|
*/ |
385
|
76 |
|
protected function getStructAttribute(StructAttributeModel $attribute = null) |
386
|
|
|
{ |
387
|
76 |
|
$struct = $this->getModel(); |
388
|
76 |
|
if (empty($attribute) && $struct instanceof StructModel && $struct->getAttributes()->count() === 1) { |
389
|
28 |
|
$attribute = $struct->getAttributes()->offsetGet(0); |
390
|
21 |
|
} |
391
|
76 |
|
return $attribute; |
392
|
|
|
} |
393
|
|
|
/** |
394
|
|
|
* @param StructAttributeModel $attribute |
395
|
|
|
* @return StructModel|null |
396
|
|
|
*/ |
397
|
76 |
|
protected function getModelFromStructAttribute(StructAttributeModel $attribute = null) |
398
|
|
|
{ |
399
|
76 |
|
$model = null; |
400
|
76 |
|
$attribute = $this->getStructAttribute($attribute); |
401
|
76 |
|
if ($attribute instanceof StructAttributeModel) { |
402
|
76 |
|
$model = $attribute->getTypeStruct(); |
403
|
57 |
|
} |
404
|
76 |
|
return $model; |
405
|
|
|
} |
406
|
|
|
/** |
407
|
|
|
* @param StructAttributeModel $attribute |
408
|
|
|
* @return StructModel|null |
409
|
|
|
*/ |
410
|
76 |
|
protected function getRestrictionFromStructAttribute(StructAttributeModel $attribute = null) |
411
|
|
|
{ |
412
|
76 |
|
$model = $this->getModelFromStructAttribute($attribute); |
413
|
76 |
|
if ($model instanceof StructModel && !$model->getIsRestriction()) { |
414
|
56 |
|
$model = null; |
415
|
42 |
|
} |
416
|
76 |
|
return $model; |
417
|
|
|
} |
418
|
|
|
/** |
419
|
|
|
* @param StructAttributeModel $attribute |
420
|
|
|
* @param bool $namespaced |
421
|
|
|
* @return string |
422
|
|
|
*/ |
423
|
76 |
|
protected function getStructAttributeType(StructAttributeModel $attribute = null, $namespaced = false) |
424
|
|
|
{ |
425
|
76 |
|
$attribute = $this->getStructAttribute($attribute); |
426
|
76 |
|
$inheritance = $attribute->getInheritance(); |
427
|
76 |
|
$type = empty($inheritance) ? $attribute->getType() : $inheritance; |
428
|
76 |
|
$model = $this->getModelFromStructAttribute($attribute); |
429
|
76 |
|
if ($model instanceof StructModel) { |
430
|
64 |
|
$modelInheritance = $model->getInheritance(); |
431
|
64 |
|
if ($model->getIsStruct() === false) { |
432
|
12 |
|
$type = !empty($modelInheritance) ? $modelInheritance : $type; |
433
|
64 |
|
} elseif ($model->getIsRestriction() === true) { |
434
|
40 |
|
$type = !empty($modelInheritance) ? $modelInheritance : self::TYPE_STRING; |
435
|
30 |
|
} else { |
436
|
52 |
|
$type = $model->getPackagedName($namespaced); |
437
|
|
|
} |
438
|
48 |
|
} |
439
|
76 |
|
return $type; |
440
|
|
|
} |
441
|
|
|
/** |
442
|
|
|
* @param StructAttributeModel $attribute |
443
|
|
|
* @param bool $returnArrayType |
444
|
|
|
* @return string |
445
|
|
|
*/ |
446
|
76 |
|
protected function getStructAttributeTypeGetAnnotation(StructAttributeModel $attribute = null, $returnArrayType = true) |
447
|
|
|
{ |
448
|
76 |
|
$attribute = $this->getStructAttribute($attribute); |
449
|
76 |
|
return sprintf('%s%s%s', $this->getStructAttributeType($attribute, true), $this->useBrackets($attribute, $returnArrayType) ? '[]' : '', $attribute->isRequired() ? '' : '|null'); |
450
|
|
|
} |
451
|
|
|
/** |
452
|
|
|
* @param StructAttributeModel $attribute |
453
|
|
|
* @param bool $returnArrayType |
454
|
|
|
* @return string |
455
|
|
|
*/ |
456
|
76 |
|
protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute = null, $returnArrayType = true) |
457
|
|
|
{ |
458
|
76 |
|
$attribute = $this->getStructAttribute($attribute); |
459
|
76 |
|
return sprintf('%s%s', $this->getStructAttributeType($attribute, true), $this->useBrackets($attribute, $returnArrayType) ? '[]' : ''); |
460
|
|
|
} |
461
|
|
|
/** |
462
|
|
|
* @param StructAttributeModel $attribute |
463
|
|
|
* @param string $returnArrayType |
464
|
|
|
* @return bool |
465
|
|
|
*/ |
466
|
76 |
|
protected function useBrackets(StructAttributeModel $attribute, $returnArrayType = true) |
467
|
|
|
{ |
468
|
76 |
|
return $returnArrayType && $attribute->isArray(); |
469
|
|
|
} |
470
|
|
|
/** |
471
|
|
|
* @param StructAttributeModel $attribute |
472
|
|
|
* @param bool $returnArrayType |
473
|
|
|
* @return string |
474
|
|
|
*/ |
475
|
76 |
|
protected function getStructAttributeTypeHint(StructAttributeModel $attribute = null, $returnArrayType = true) |
476
|
|
|
{ |
477
|
76 |
|
$attribute = $this->getStructAttribute($attribute); |
478
|
76 |
|
return ($returnArrayType && $attribute->isArray()) ? self::TYPE_ARRAY : $this->getStructAttributeType($attribute, true); |
479
|
|
|
} |
480
|
|
|
/** |
481
|
|
|
* See http://php.net/manual/fr/language.oop5.typehinting.php for these cases |
482
|
|
|
* Also see http://www.w3schools.com/schema/schema_dtypes_numeric.asp |
483
|
|
|
* @param mixed $type |
484
|
|
|
* @param mixed $fallback |
485
|
|
|
* @return mixed |
486
|
|
|
*/ |
487
|
76 |
|
public static function getValidType($type, $fallback = null) |
488
|
|
|
{ |
489
|
76 |
|
return XsdTypes::instance()->isXsd(str_replace('[]', '', $type)) ? $fallback : $type; |
490
|
|
|
} |
491
|
|
|
/** |
492
|
|
|
* See http://php.net/manual/fr/language.oop5.typehinting.php for these cases |
493
|
|
|
* Also see http://www.w3schools.com/schema/schema_dtypes_numeric.asp |
494
|
|
|
* @param mixed $type |
495
|
|
|
* @param mixed $fallback |
496
|
|
|
* @return mixed |
497
|
|
|
*/ |
498
|
24 |
|
public static function getPhpType($type, $fallback = self::TYPE_STRING) |
499
|
|
|
{ |
500
|
24 |
|
return XsdTypes::instance()->isXsd(str_replace('[]', '', $type)) ? XsdTypes::instance()->phpType($type) : $fallback; |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
|