forked from agussuroyo/wp-api-swaggerui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swaggerbag.php
50 lines (36 loc) · 849 Bytes
/
swaggerbag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
class SwaggerBag {
public $items = [];
public function __construct( $items = [] ) {
$this->replace( $items );
}
public function replace( $items = [] ) {
$this->items = $items;
}
public function set( $name, $value ) {
$this->items[$name] = $value;
}
public function get( $name ) {
return isset( $this->items[$name] ) ? $this->items[$name] : null;
}
public function has( $name ) {
return array_key_exists( $name, $this->items );
}
public function all() {
return $this->items;
}
public function keys() {
return array_keys( $this->items );
}
public function only( $name ) {
$look = is_array( $name ) ? $name : func_get_args();
$all = $this->all();
$filtered = [];
foreach ( $look as $key ) {
if ( isset( $all[$key] ) ) {
$filtered[$key] = $all[$key];
}
}
return $filtered;
}
}