|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* It's free open-source software released under the MIT License. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Anatoly Fenric <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Fenric |
|
8
|
|
|
* @license https://github.com/sunrise-php/http-router/blob/master/LICENSE |
|
9
|
|
|
* @link https://github.com/sunrise-php/http-router |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sunrise\Http\Router\Annotation\OpenApi; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Import classes |
|
16
|
|
|
*/ |
|
17
|
|
|
use Doctrine\Common\Annotations\SimpleAnnotationReader; |
|
18
|
|
|
use Sunrise\Http\Router\OpenApi\AbstractObject; |
|
19
|
|
|
use Sunrise\Http\Router\OpenApi\ComponentObjectInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Import functions |
|
23
|
|
|
*/ |
|
24
|
|
|
use function array_merge; |
|
25
|
|
|
use function array_walk_recursive; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* AbstractAnnotation |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract class AbstractAnnotation extends AbstractObject |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Recursively collects all annotations referenced by this object or its children |
|
35
|
|
|
* |
|
36
|
|
|
* @param SimpleAnnotationReader $annotationReader |
|
37
|
|
|
* |
|
38
|
|
|
* @return ComponentObjectInterface[] |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getReferencedObjects(SimpleAnnotationReader $annotationReader) : array |
|
41
|
|
|
{ |
|
42
|
|
|
$fields = $this->getFields(); |
|
43
|
|
|
$objects = []; |
|
44
|
|
|
|
|
45
|
|
|
array_walk_recursive($fields, function ($value) use ($annotationReader, &$objects) { |
|
46
|
|
|
if ($value instanceof AbstractAnnotation) { |
|
47
|
|
|
$objects = array_merge($objects, $value->getReferencedObjects($annotationReader)); |
|
48
|
|
|
} elseif ($value instanceof AbstractReference) { |
|
49
|
|
|
$object = $value->getAnnotation($annotationReader); |
|
50
|
|
|
$objects[] = $object; |
|
51
|
|
|
|
|
52
|
|
|
if ($object instanceof AbstractAnnotation) { |
|
53
|
|
|
$objects = array_merge($objects, $object->getReferencedObjects($annotationReader)); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
return $objects; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|