|
1
|
|
|
<?php declare(strict_types = 1); |
|
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 KleijnWeb\SwaggerBundle\Document\Specification\Operation; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author John Kleijn <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class Specification |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var object |
|
20
|
|
|
*/ |
|
21
|
|
|
private $definition; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Operation[] |
|
25
|
|
|
*/ |
|
26
|
|
|
private $operations; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param \stdClass $definition |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(\stdClass $definition) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->definition = $definition; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $typeName |
|
38
|
|
|
* |
|
39
|
|
|
* @return \stdClass |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getResourceDefinition(string $typeName): \stdClass |
|
42
|
|
|
{ |
|
43
|
|
|
if (!isset($this->definition->definitions->$typeName)) { |
|
44
|
|
|
throw new \InvalidArgumentException("Unknown resource type name '$typeName'"); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->definition->definitions->$typeName; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return \stdClass |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getDefinition(): \stdClass |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->definition; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return \stdClass |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getPaths(): \stdClass |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->definition->paths; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $path |
|
68
|
|
|
* @param string $method |
|
69
|
|
|
* |
|
70
|
|
|
* @return Operation |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getOperation(string $path, string $method): Operation |
|
73
|
|
|
{ |
|
74
|
|
|
$key = "$path::$method"; |
|
75
|
|
|
|
|
76
|
|
|
if (isset($this->operations[$key])) { |
|
77
|
|
|
return $this->operations[$key]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $this->operations[$key] = new Operation($this, $path, $method); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @deprecated |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $path |
|
87
|
|
|
* @param string $method |
|
88
|
|
|
* |
|
89
|
|
|
* @return \stdClass |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getOperationDefinition(string $path, string $method): \stdClass |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->getOperation($path, $method)->getDefinition(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|