1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the KleijnWeb\SwaggerBundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace KleijnWeb\SwaggerBundle\Document; |
10
|
|
|
|
11
|
|
|
use Symfony\Component\Yaml\Yaml; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author John Kleijn <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class SwaggerDocument |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $uri; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var object |
25
|
|
|
*/ |
26
|
|
|
private $definition; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var OperationObject[] |
30
|
|
|
*/ |
31
|
|
|
private $operations; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $pathFileName |
35
|
|
|
* @param object $definition |
36
|
|
|
*/ |
37
|
|
|
public function __construct($pathFileName, $definition) |
38
|
|
|
{ |
39
|
|
|
$this->uri = $pathFileName; |
40
|
|
|
$this->definition = $definition; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return object |
45
|
|
|
*/ |
46
|
|
|
public function getDefinition() |
47
|
|
|
{ |
48
|
|
|
return $this->definition; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return object |
53
|
|
|
*/ |
54
|
|
|
public function getPathDefinitions() |
55
|
|
|
{ |
56
|
|
|
return $this->definition->paths; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return object |
61
|
|
|
*/ |
62
|
|
|
public function getResourceSchemas() |
63
|
|
|
{ |
64
|
|
|
return $this->definition->definitions; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getBasePath() |
71
|
|
|
{ |
72
|
|
|
return $this->definition->basePath; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $path |
77
|
|
|
* @param string $method |
78
|
|
|
* |
79
|
|
|
* @return OperationObject |
80
|
|
|
*/ |
81
|
|
|
public function getOperationObject($path, $method) |
82
|
|
|
{ |
83
|
|
|
$key = "$path::$method"; |
84
|
|
|
|
85
|
|
|
if (isset($this->operations[$key])) { |
86
|
|
|
return $this->operations[$key]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $this->operations[$key] = new OperationObject($this, $path, $method); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @deprecated |
94
|
|
|
* |
95
|
|
|
* @param string $path |
96
|
|
|
* @param string $method |
97
|
|
|
* |
98
|
|
|
* @return object |
99
|
|
|
*/ |
100
|
|
|
public function getOperationDefinition($path, $method) |
101
|
|
|
{ |
102
|
|
|
return $this->getOperationObject($path, $method)->getDefinition(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getUri() |
109
|
|
|
{ |
110
|
|
|
return $this->uri; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|