12
12
/**
13
13
* Get an item of `GET` data if set, otherwise return a default value.
14
14
*
15
+ * @template T
15
16
* @param string $key GET key.
16
- * @param string $def Default value.
17
- * @return mixed Value sanitized by xwp_uclean.
17
+ * @param null|T $def Default value.
18
+ * @return T
18
19
*/
19
- function xwp_fetch_get_var ( $ key , $ def = null ) {
20
+ function xwp_fetch_get_var ( string $ key , mixed $ def = null ): mixed {
20
21
return f \Request::fetch_get_var ( $ key , $ def );
21
22
}
22
23
endif ;
@@ -25,11 +26,12 @@ function xwp_fetch_get_var( $key, $def = null ) {
25
26
/**
26
27
* Get an item of `POST` data if set, otherwise return a default value.
27
28
*
28
- * @param string $key POST key.
29
- * @param string $def Default value.
30
- * @return mixed Value sanitized by xwp_uclean.
29
+ * @template T
30
+ * @param string $key POST key.
31
+ * @param null|T $def Default value.
32
+ * @return T Value sanitized by xwp_uclean.
31
33
*/
32
- function xwp_fetch_post_var ( $ key , $ def = null ) {
34
+ function xwp_fetch_post_var ( string $ key , mixed $ def = null ): mixed {
33
35
return f \Request::fetch_post_var ( $ key , $ def );
34
36
}
35
37
endif ;
@@ -38,9 +40,10 @@ function xwp_fetch_post_var( $key, $def = null ) {
38
40
/**
39
41
* Get an item of `REQUEST`data if set, otherwise return a default value.
40
42
*
41
- * @param string $key REQUEST key.
42
- * @param string $def Default value.
43
- * @return mixed Value sanitized by xwp_uclean.
43
+ * @template T
44
+ * @param string $key REQUEST key.
45
+ * @param null|T $def Default value.
46
+ * @return T Value sanitized by xwp_uclean.
44
47
*/
45
48
function xwp_fetch_req_var ( $ key , $ def = null ) {
46
49
return f \Request::fetch_req_var ( $ key , $ def );
@@ -51,11 +54,12 @@ function xwp_fetch_req_var( $key, $def = null ) {
51
54
/**
52
55
* Get an item of `SERVER` data if set, otherwise return a default value.
53
56
*
54
- * @param string $key SERVER key.
55
- * @param string $def Default value.
56
- * @return mixed Value sanitized by xwp_uclean.
57
+ * @template T
58
+ * @param string $key SERVER key.
59
+ * @param null|T $def Default value.
60
+ * @return T Value sanitized by xwp_uclean.
57
61
*/
58
- function xwp_fetch_server_var ( $ key , $ def = null ) {
62
+ function xwp_fetch_server_var ( string $ key , mixed $ def = null ): mixed {
59
63
return f \Request::fetch_server_var ( $ key , $ def );
60
64
}
61
65
endif ;
@@ -64,11 +68,11 @@ function xwp_fetch_server_var( $key, $def = null ) {
64
68
/**
65
69
* Get an item of `COOKIE` data if set, otherwise return a default value.
66
70
*
67
- * @param string $key COOKIE key.
68
- * @param string $def Default value.
69
- * @return mixed Value sanitized by xwp_uclean.
71
+ * @param string $key COOKIE key.
72
+ * @param string $def Default value.
73
+ * @return string Value sanitized by xwp_uclean.
70
74
*/
71
- function xwp_fetch_cookie_var ( $ key , $ def = null ) {
75
+ function xwp_fetch_cookie_var ( string $ key , string $ def = '' ): string {
72
76
return f \Request::fetch_cookie_var ( $ key , $ def );
73
77
}
74
78
endif ;
@@ -90,32 +94,38 @@ function xwp_fetch_files_var( $key, $def = null ) {
90
94
/**
91
95
* Get the unslashed and cleaned $_GET array.
92
96
*
93
- * @return array<string, mixed>
97
+ * @template T of array
98
+ * @param T $def Default value.
99
+ * @return T
94
100
*/
95
- function xwp_get_arr (): array {
96
- return f \Request::fetch_get_arr ();
101
+ function xwp_get_arr ( array $ def = array () ): array {
102
+ return xwp_parse_args ( f \Request::fetch_get_arr (), $ def );
97
103
}
98
104
endif ;
99
105
100
106
if ( ! function_exists ( 'xwp_post_arr ' ) ) :
101
107
/**
102
108
* Get the unslashed and cleaned $_POST array.
103
109
*
104
- * @return array<string, mixed>
110
+ * @template T of array
111
+ * @param T $def Default value.
112
+ * @return T
105
113
*/
106
- function xwp_post_arr (): array {
107
- return f \Request::fetch_post_arr ();
114
+ function xwp_post_arr ( array $ def = array () ): array {
115
+ return xwp_parse_args ( f \Request::fetch_post_arr (), $ def );
108
116
}
109
117
endif ;
110
118
111
119
if ( ! function_exists ( 'xwp_req_arr ' ) ) :
112
120
/**
113
121
* Get the unslashed and cleaned $_REQUEST array.
114
122
*
115
- * @return array<string, mixed>
123
+ * @template T of array
124
+ * @param T $def Default value.
125
+ * @return T
116
126
*/
117
- function xwp_req_arr (): array {
118
- return f \Request::fetch_req_arr ();
127
+ function xwp_req_arr ( array $ def = array () ): array {
128
+ return xwp_parse_args ( f \Request::fetch_req_arr (), $ def );
119
129
}
120
130
endif ;
121
131
0 commit comments