1
|
|
|
<?php |
2
|
|
|
namespace gossi\swagger\collections; |
3
|
|
|
|
4
|
|
|
use gossi\swagger\AbstractModel; |
5
|
|
|
use gossi\swagger\SecurityScheme; |
6
|
|
|
use phootwork\collection\CollectionUtils; |
7
|
|
|
use phootwork\collection\Map; |
8
|
|
|
use phootwork\lang\Arrayable; |
9
|
|
|
|
10
|
|
|
class SecurityDefinitions extends AbstractModel implements Arrayable, \Iterator { |
11
|
|
|
|
12
|
|
|
/** @var Map */ |
13
|
|
|
private $schemes; |
14
|
|
|
|
15
|
|
|
public function __construct($contents = []) { |
16
|
|
|
$this->parse($contents === null ? [] : $contents); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
private function parse($contents) { |
20
|
|
|
$data = CollectionUtils::toMap($contents); |
21
|
|
|
|
22
|
|
|
// schemes |
23
|
|
|
$this->schemes = new Map(); |
24
|
|
|
foreach ($data as $id => $scheme) { |
25
|
|
|
$this->schemes->set($id, new SecurityScheme($id, $scheme)); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function toArray() { |
30
|
|
|
return CollectionUtils::toArrayRecursive($this->schemes); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function size() { |
34
|
|
|
return $this->schemes->size(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns whether a scheme with the given id exists |
39
|
|
|
* |
40
|
|
|
* @param string $id |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function has($id) { |
44
|
|
|
return $this->schemes->has($id); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns whether the given scheme exists |
49
|
|
|
* |
50
|
|
|
* @param SecurityScheme $scheme |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function contains(SecurityScheme $scheme) { |
54
|
|
|
return $this->schemes->contains($scheme); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns the scheme info for the given id |
59
|
|
|
* |
60
|
|
|
* @param string $id |
61
|
|
|
* @return SecurityScheme |
62
|
|
|
*/ |
63
|
|
|
public function get($id) { |
64
|
|
|
if (!$this->schemes->has($id)) { |
65
|
|
|
$this->schemes->set($id, new SecurityScheme($id)); |
66
|
|
|
} |
67
|
|
|
return $this->schemes->get($id); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Sets the scheme |
72
|
|
|
* |
73
|
|
|
* @param SecurityScheme $scheme |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
|
|
public function add(SecurityScheme $scheme) { |
77
|
|
|
$this->schemes->set($scheme->getId(), $scheme); |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Adds all schemes from another definitions collection. Will overwrite existing operations. |
83
|
|
|
* |
84
|
|
|
* @param SecurityDefinitions $schemes |
|
|
|
|
85
|
|
|
*/ |
86
|
|
|
public function addAll(SecurityDefinitions $definitions) { |
87
|
|
|
foreach ($definitions as $scheme) { |
88
|
|
|
$this->add($scheme); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Removes the given scheme |
94
|
|
|
* |
95
|
|
|
* @param string $scheme |
96
|
|
|
*/ |
97
|
|
|
public function remove($scheme) { |
98
|
|
|
$this->schemes->remove($scheme); |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function current() { |
103
|
|
|
return $this->schemes->current(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function key() { |
107
|
|
|
return $this->schemes->key(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function next() { |
111
|
|
|
return $this->schemes->next(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function rewind() { |
115
|
|
|
return $this->schemes->rewind(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function valid() { |
119
|
|
|
return $this->schemes->valid(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.