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 ReflectionClass; |
19
|
|
|
use ReflectionMethod; |
20
|
|
|
use ReflectionProperty; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Import functions |
24
|
|
|
*/ |
25
|
|
|
use function sprintf; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* AbstractReference |
29
|
|
|
* |
30
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#reference-object |
31
|
|
|
*/ |
32
|
|
|
abstract class AbstractReference extends AbstractAnnotation |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @Required |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
public $name; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @Required |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
public $class; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
public $method; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
public $property; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
abstract public function getAnnotationName() : string; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
abstract public function getComponentName() : string; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param SimpleAnnotationReader $annotationReader |
71
|
|
|
* |
72
|
|
|
* @return null|AbstractAnnotation |
73
|
|
|
*/ |
74
|
|
|
public function getAnnotation(SimpleAnnotationReader $annotationReader) : ?AbstractAnnotation |
75
|
|
|
{ |
76
|
|
|
if (isset($this->method)) { |
77
|
|
|
return $annotationReader->getMethodAnnotation( |
78
|
|
|
new ReflectionMethod($this->class, $this->method), |
79
|
|
|
$this->getAnnotationName() |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (isset($this->property)) { |
84
|
|
|
return $annotationReader->getPropertyAnnotation( |
85
|
|
|
new ReflectionProperty($this->class, $this->property), |
86
|
|
|
$this->getAnnotationName() |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $annotationReader->getClassAnnotation( |
91
|
|
|
new ReflectionClass($this->class), |
92
|
|
|
$this->getAnnotationName() |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getComponentPath() : string |
100
|
|
|
{ |
101
|
|
|
return sprintf('#/components/%s/%s', $this->getComponentName(), $this->name); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritDoc} |
106
|
|
|
*/ |
107
|
|
|
public function toArray() : array |
108
|
|
|
{ |
109
|
|
|
return ['$ref' => $this]; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|