Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit c648075

Browse files
committed
Merge branch 'master' into v1.5
2 parents a0b8bb8 + 4f34b01 commit c648075

7 files changed

Lines changed: 154 additions & 17 deletions

File tree

CHANGELOG-1.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# CHANGELOG for 1.X
22

3-
## v1.5.0
3+
## v1.5.2
44

5-
### 添加
6-
- 命令行添加 `callSystem()` 接口, 允许至今调用系统命令, 如: ls, mkdir, sed, awk 等
5+
### 修正
6+
- 修正获取请求头部信息
7+
- Request 添加 acceptWebP 方法判断浏览器是否支持 webp
8+
- 时区从配置文件读取
79

8-
### 变动
9-
- Request 和 Response 使用 [Symfony/http-foundation](https://github.com/symfony/http-foundation) 代替
10+
## v1.5.1
1011

11-
### 修正
12+
- 命令行添加 `callSystem()` 接口, 允许至今调用系统命令, 如: ls, mkdir, sed, awk 等
13+
- Request 和 Response 使用 [Symfony/http-foundation](https://github.com/symfony/http-foundation) 代替
1214
- 修改 Request 获取 ip, 判断 pjax 问题

src/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class App extends Container
6363
public function __construct($path, $environment)
6464
{
6565
mb_internal_encoding('UTF-8');
66-
date_default_timezone_set('Asia/Shanghai');
66+
date_default_timezone_set($this->configGet('app.timezone', 'Asia/Shanghai'));
6767

6868
// 记录程序运行环境
6969
$this->basePath = $path;

src/Component.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace awheel;
44

5+
use Closure;
6+
57
/**
68
* 组件接口
79
* todo 组件可以设置实例化的环境: Http|Console|Both
@@ -13,14 +15,14 @@ interface Component
1315
/**
1416
* 组件访问器
1517
*
16-
* @return mixed
18+
* @return string
1719
*/
1820
public function getAccessor();
1921

2022
/**
2123
* 组件注册方法
2224
*
23-
* @return mixed
25+
* @return Closure
2426
*/
2527
public function register();
2628
}

src/Console/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function handle(Input $input, Output $output = null)
7575
public function resolveCommands($commands)
7676
{
7777
$consoleApp = new Application($this->app->name(), App::VERSION);
78+
$consoleApp->setCatchExceptions(!$this->app->configGet('app.debug'));
7879

7980
foreach ($commands as $command) {
8081
$consoleApp->add(new $command);

src/Http/Request.php

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

src/Support/LogComponent.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515
class LogComponent implements Component
1616
{
1717
/**
18-
* 组件访问器
19-
*
20-
* @return mixed
18+
* @inheritdoc
2119
*/
2220
public function getAccessor()
2321
{
2422
return 'log';
2523
}
2624

2725
/**
28-
* 组件注册方法
29-
*
30-
* @return mixed
26+
* @inheritdoc
3127
*/
3228
public function register()
3329
{

test/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)