Skip to content

Commit

Permalink
Merge branch 'master' into v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fengqi committed Apr 17, 2017
2 parents a0b8bb8 + 4f34b01 commit c648075
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 17 deletions.
14 changes: 8 additions & 6 deletions CHANGELOG-1.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# CHANGELOG for 1.X

## v1.5.0
## v1.5.2

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

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

### 修正
- 命令行添加 `callSystem()` 接口, 允许至今调用系统命令, 如: ls, mkdir, sed, awk 等
- Request 和 Response 使用 [Symfony/http-foundation](https://github.com/symfony/http-foundation) 代替
- 修改 Request 获取 ip, 判断 pjax 问题
2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class App extends Container
public function __construct($path, $environment)
{
mb_internal_encoding('UTF-8');
date_default_timezone_set('Asia/Shanghai');
date_default_timezone_set($this->configGet('app.timezone', 'Asia/Shanghai'));

// 记录程序运行环境
$this->basePath = $path;
Expand Down
6 changes: 4 additions & 2 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace awheel;

use Closure;

/**
* 组件接口
* todo 组件可以设置实例化的环境: Http|Console|Both
Expand All @@ -13,14 +15,14 @@ interface Component
/**
* 组件访问器
*
* @return mixed
* @return string
*/
public function getAccessor();

/**
* 组件注册方法
*
* @return mixed
* @return Closure
*/
public function register();
}
1 change: 1 addition & 0 deletions src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function handle(Input $input, Output $output = null)
public function resolveCommands($commands)
{
$consoleApp = new Application($this->app->name(), App::VERSION);
$consoleApp->setCatchExceptions(!$this->app->configGet('app.debug'));

foreach ($commands as $command) {
$consoleApp->add(new $command);
Expand Down
140 changes: 138 additions & 2 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,104 @@ public function all()
return array_replace_recursive($this->input(), $this->files->all());
}

/**
* 获取上传的文件
*
* @param $key
*
* @return mixed
*/
public function file($key)
{
return $this->files->get($key);
}

/**
* 判断是否有上传文件
*
* @param $key
*
* @return bool
*/
public function hasFile($key)
{
return $this->files->has($key);
}

/**
* 获取指定名称的 cookie
*
* @param $key
* @param null $default
*
* @return mixed
*/
public function cookie($key, $default = null)
{
return $this->cookies->get($key, $default);
}

/**
* 返回 Request 全部 cookie
*
* @return array
*/
public function cookies()
{
return $this->cookies->all();
}

/**
* 检查 Request 中是否有某个名称的 cookie
*
* @param $key
*
* @return bool
*/
public function hasCookie($key)
{
return $this->cookies->has($key);
}

/**
* @deprecated
* @return string
*/
public function baseUrl()
{
return rtrim(app()->configGet('app.base_url'), '/');
}

/**
* 获取当前 url, 不带参数
*
* @return string
*/
public function url()
{
return $this->getUriForPath();
}

/**
* 返回请求的 uri
*
* @return string
*/
public function uri()
{
return $this->getRequestUri();
}

/**
* 返回带完整的请求 uri
*
* @return string
*/
public function fullUri()
{
return $this->getUri();
}

/**
* 获取用户输入, example: request('name', 'default_name'); request(['id', 'name'], ['name' => 'default_name'])
*
Expand Down Expand Up @@ -110,6 +208,42 @@ public function segments()
return explode('/', $this->getPathInfo());
}

/**
* 获取请求的指定 header
*
* @param $key
* @param null $default
*
* @return array|string
*/
public function header($key, $default = null)
{
return $this->headers->get($key, $default);
}

/**
* 获取请求的全部 header
*
* @return array
*/
public function getHeaders()
{
return $this->headers->all();
}

/**
* 从 $_SERVER 中获取变量
*
* @param $key
* @param null $default
*
* @return mixed
*/
public function server($key, $default = null)
{
return $this->server->get($key, $default);
}

/**
* 是否是 ajax 请求, 使用 X-Requested-With 头判断
*
Expand Down Expand Up @@ -184,11 +318,13 @@ public function isMobile()
/**
* 判断是否支持 WebP
*
* @param string $param
*
* @return int
*/
public function acceptWebP()
public function acceptWebP($param = 'accept_webp')
{
return is_int(stripos($this->server->get('HTTP_ACCEPT'), 'webp')) || (bool)$this->get('accept_webp') == true;
return is_int(stripos($this->server->get('HTTP_ACCEPT'), 'webp')) || (bool)$this->get($param) == true;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Support/LogComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
class LogComponent implements Component
{
/**
* 组件访问器
*
* @return mixed
* @inheritdoc
*/
public function getAccessor()
{
return 'log';
}

/**
* 组件注册方法
*
* @return mixed
* @inheritdoc
*/
public function register()
{
Expand Down
Empty file added test/.gitkeep
Empty file.

0 comments on commit c648075

Please sign in to comment.