| @@ 358-398 (lines=41) @@ | ||
| 355 | * |
|
| 356 | * @return string|null |
|
| 357 | */ |
|
| 358 | private function getRange(PropertyMetadata $propertyMetadata) |
|
| 359 | { |
|
| 360 | $type = $propertyMetadata->getType(); |
|
| 361 | if (!$type) { |
|
| 362 | return; |
|
| 363 | } |
|
| 364 | ||
| 365 | if ($type->isCollection() && $collectionType = $type->getCollectionValueType()) { |
|
| 366 | $type = $collectionType; |
|
| 367 | } |
|
| 368 | ||
| 369 | switch ($type->getBuiltinType()) { |
|
| 370 | case Type::BUILTIN_TYPE_STRING: |
|
| 371 | return 'xmls:string'; |
|
| 372 | ||
| 373 | case Type::BUILTIN_TYPE_INT: |
|
| 374 | return 'xmls:integer'; |
|
| 375 | ||
| 376 | case Type::BUILTIN_TYPE_FLOAT: |
|
| 377 | return 'xmls:number'; |
|
| 378 | ||
| 379 | case Type::BUILTIN_TYPE_BOOL: |
|
| 380 | return 'xmls:boolean'; |
|
| 381 | ||
| 382 | case Type::BUILTIN_TYPE_OBJECT: |
|
| 383 | $className = $type->getClassName(); |
|
| 384 | ||
| 385 | if (null !== $className) { |
|
| 386 | $reflection = new \ReflectionClass($className); |
|
| 387 | if ($reflection->implementsInterface(\DateTimeInterface::class)) { |
|
| 388 | return 'xmls:dateTime'; |
|
| 389 | } |
|
| 390 | ||
| 391 | $className = $type->getClassName(); |
|
| 392 | if ($this->resourceClassResolver->isResourceClass($className)) { |
|
| 393 | return sprintf('#%s', $this->resourceMetadataFactory->create($className)->getShortName()); |
|
| 394 | } |
|
| 395 | } |
|
| 396 | break; |
|
| 397 | } |
|
| 398 | } |
|
| 399 | ||
| 400 | /** |
|
| 401 | * Builds the JSON-LD context for the API documentation. |
|
| @@ 299-342 (lines=44) @@ | ||
| 296 | * |
|
| 297 | * @return string|null |
|
| 298 | */ |
|
| 299 | private function getRange(PropertyMetadata $propertyMetadata) |
|
| 300 | { |
|
| 301 | $type = $propertyMetadata->getType(); |
|
| 302 | if (!$type) { |
|
| 303 | return; |
|
| 304 | } |
|
| 305 | ||
| 306 | if ($type->isCollection() && $collectionType = $type->getCollectionValueType()) { |
|
| 307 | $type = $collectionType; |
|
| 308 | } |
|
| 309 | ||
| 310 | switch ($type->getBuiltinType()) { |
|
| 311 | case Type::BUILTIN_TYPE_STRING: |
|
| 312 | return 'string'; |
|
| 313 | ||
| 314 | case Type::BUILTIN_TYPE_INT: |
|
| 315 | return 'integer'; |
|
| 316 | ||
| 317 | case Type::BUILTIN_TYPE_FLOAT: |
|
| 318 | return 'number'; |
|
| 319 | ||
| 320 | case Type::BUILTIN_TYPE_BOOL: |
|
| 321 | return 'boolean'; |
|
| 322 | ||
| 323 | case Type::BUILTIN_TYPE_OBJECT: |
|
| 324 | $className = $type->getClassName(); |
|
| 325 | ||
| 326 | if (null !== $className) { |
|
| 327 | $reflection = new \ReflectionClass($className); |
|
| 328 | if ($reflection->implementsInterface(\DateTimeInterface::class)) { |
|
| 329 | return 'string'; |
|
| 330 | } |
|
| 331 | ||
| 332 | $className = $type->getClassName(); |
|
| 333 | if ($this->resourceClassResolver->isResourceClass($className)) { |
|
| 334 | return ['$ref' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())]; |
|
| 335 | } |
|
| 336 | } |
|
| 337 | break; |
|
| 338 | default: |
|
| 339 | return 'null'; |
|
| 340 | break; |
|
| 341 | } |
|
| 342 | } |
|
| 343 | } |
|
| 344 | ||