-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFilters.php
126 lines (107 loc) · 3.07 KB
/
Filters.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace WPOpenAPI;
use WPOpenAPI\Spec\Info;
use WPOpenAPI\Spec\Operation;
use WPOpenAPI\Spec\Path;
use WPOpenAPI\Spec\Tag;
class Filters {
const PREFIX = 'wp-openapi-';
private static ?Filters $instance = null;
public static function getInstance(): Filters {
if ( static::$instance === null ) {
static::$instance = new static();
}
return static::$instance;
}
/**
* @param $callback
* @param int $priority
* @return void
*/
public function addOperationsFilter( $callback, int $priority = 10 ) {
add_filter( self::PREFIX . 'filter-operations', $callback, $priority, 2 );
}
/**
* @param Operation[] $operations
* @param array $args
* @return Operation[]
*/
public function applyOperationsFilters( array $operations, array $args = array() ): array {
return apply_filters( self::PREFIX . 'filter-operations', $operations, $args );
}
public function addPathsFilter( $callback, $priority = 10 ) {
add_filter( self::PREFIX . 'filter-paths', $callback, $priority, 2 );
}
/**
* @param Path[] $paths
* @param array $args
* @return Path[]
*/
public function applyPathsFilters( array $paths, array $args = array() ): array {
return apply_filters( self::PREFIX . 'filter-paths', $paths, $args );
}
/**
* @param $callback
* @param int $priority
* @return void
*/
public function addServersFilter( $callback, int $priority = 10 ) {
add_filter( self::PREFIX . 'filter-servers', $callback, $priority, 2 );
}
/**
* @param array $servers
* @param array $args
* @return array
*/
public function applyServersFilters( array $servers, array $args = array() ): array {
return apply_filters( self::PREFIX . 'filter-servers', $servers, $args );
}
/**
* @param $callback
* @param int $priority
* @return void
*/
public function addInfoFilter( $callback, int $priority = 10 ) {
add_filter( self::PREFIX . 'filter-info', $callback, $priority, 2 );
}
/**
* @param Info $info
* @param array $args
* @return Info
*/
public function applyInfoFilters( Info $info, array $args = array() ): Info {
return apply_filters( self::PREFIX . 'filter-info', $info, $args );
}
/**
* @param array $components
* @param array $args
* @return array
*/
public function applyComponentsFilters( array $components, array $args = array() ): array {
return apply_filters( self::PREFIX . 'filter-components', $components, $args );
}
/**
* @param $callback
* @param int $priority
* @return bool|true|void
*/
public function addComponentsFilter( $callback, int $priority = 10 ) {
return add_filter( self::PREFIX . 'filter-components', $callback, $priority, 2 );
}
/**
* @param Tag[] $tags
* @param array $args
* @return Tag[]
*/
public function applyTagsFilters( array $tags, array $args = array() ): array {
return apply_filters( self::PREFIX . 'filter-tags', $tags, $args );
}
/**
* @param $callback
* @param int $priority
* @return bool|true|void
*/
public function addTagsFilter( $callback, int $priority = 10 ) {
return add_filter( self::PREFIX . 'filter-tags', $callback, $priority, 2 );
}
}