@@ -31,6 +31,104 @@ public function all()
3131 return array_replace_recursive ($ this ->input (), $ this ->files ->all ());
3232 }
3333
34+ /**
35+ * 获取上传的文件
36+ *
37+ * @param $key
38+ *
39+ * @return mixed
40+ */
41+ public function file ($ key )
42+ {
43+ return $ this ->files ->get ($ key );
44+ }
45+
46+ /**
47+ * 判断是否有上传文件
48+ *
49+ * @param $key
50+ *
51+ * @return bool
52+ */
53+ public function hasFile ($ key )
54+ {
55+ return $ this ->files ->has ($ key );
56+ }
57+
58+ /**
59+ * 获取指定名称的 cookie
60+ *
61+ * @param $key
62+ * @param null $default
63+ *
64+ * @return mixed
65+ */
66+ public function cookie ($ key , $ default = null )
67+ {
68+ return $ this ->cookies ->get ($ key , $ default );
69+ }
70+
71+ /**
72+ * 返回 Request 全部 cookie
73+ *
74+ * @return array
75+ */
76+ public function cookies ()
77+ {
78+ return $ this ->cookies ->all ();
79+ }
80+
81+ /**
82+ * 检查 Request 中是否有某个名称的 cookie
83+ *
84+ * @param $key
85+ *
86+ * @return bool
87+ */
88+ public function hasCookie ($ key )
89+ {
90+ return $ this ->cookies ->has ($ key );
91+ }
92+
93+ /**
94+ * @deprecated
95+ * @return string
96+ */
97+ public function baseUrl ()
98+ {
99+ return rtrim (app ()->configGet ('app.base_url ' ), '/ ' );
100+ }
101+
102+ /**
103+ * 获取当前 url, 不带参数
104+ *
105+ * @return string
106+ */
107+ public function url ()
108+ {
109+ return $ this ->getUriForPath ();
110+ }
111+
112+ /**
113+ * 返回请求的 uri
114+ *
115+ * @return string
116+ */
117+ public function uri ()
118+ {
119+ return $ this ->getRequestUri ();
120+ }
121+
122+ /**
123+ * 返回带完整的请求 uri
124+ *
125+ * @return string
126+ */
127+ public function fullUri ()
128+ {
129+ return $ this ->getUri ();
130+ }
131+
34132 /**
35133 * 获取用户输入, example: request('name', 'default_name'); request(['id', 'name'], ['name' => 'default_name'])
36134 *
@@ -110,6 +208,42 @@ public function segments()
110208 return explode ('/ ' , $ this ->getPathInfo ());
111209 }
112210
211+ /**
212+ * 获取请求的指定 header
213+ *
214+ * @param $key
215+ * @param null $default
216+ *
217+ * @return array|string
218+ */
219+ public function header ($ key , $ default = null )
220+ {
221+ return $ this ->headers ->get ($ key , $ default );
222+ }
223+
224+ /**
225+ * 获取请求的全部 header
226+ *
227+ * @return array
228+ */
229+ public function getHeaders ()
230+ {
231+ return $ this ->headers ->all ();
232+ }
233+
234+ /**
235+ * 从 $_SERVER 中获取变量
236+ *
237+ * @param $key
238+ * @param null $default
239+ *
240+ * @return mixed
241+ */
242+ public function server ($ key , $ default = null )
243+ {
244+ return $ this ->server ->get ($ key , $ default );
245+ }
246+
113247 /**
114248 * 是否是 ajax 请求, 使用 X-Requested-With 头判断
115249 *
@@ -184,11 +318,13 @@ public function isMobile()
184318 /**
185319 * 判断是否支持 WebP
186320 *
321+ * @param string $param
322+ *
187323 * @return int
188324 */
189- public function acceptWebP ()
325+ public function acceptWebP ($ param = ' accept_webp ' )
190326 {
191- return is_int (stripos ($ this ->server ->get ('HTTP_ACCEPT ' ), 'webp ' )) || (bool )$ this ->get (' accept_webp ' ) == true ;
327+ return is_int (stripos ($ this ->server ->get ('HTTP_ACCEPT ' ), 'webp ' )) || (bool )$ this ->get ($ param ) == true ;
192328 }
193329
194330 /**
0 commit comments