Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lisijie committed Jul 31, 2018
1 parent deb57e7 commit d0d623d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/Core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected function get($name, $default = null, $applyFilter = true)
*/
protected function getQuery($name = null, $default = null, $applyFilter = true)
{
if (null === $name) {
return $this->request->getQueryParams($applyFilter);
}
return $this->request->getQueryParam($name, $default, $applyFilter);
}

Expand All @@ -141,6 +144,9 @@ protected function getQuery($name = null, $default = null, $applyFilter = true)
*/
protected function getPost($name = null, $default = null, $applyFilter = true)
{
if (null === $name) {
return $this->request->getParsedBody($applyFilter);
}
return $this->request->getPostParam($name, $default, $applyFilter);
}

Expand Down
42 changes: 24 additions & 18 deletions src/Core/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class Request extends Message implements ServerRequestInterface
protected $serverParams = [];

/**
* @var array
* @var null|array
*/
protected $queryParams = [];
protected $queryParams = null;

/**
* @var array
Expand Down Expand Up @@ -337,21 +337,23 @@ public function withUri(UriInterface $uri, $preserveHost = false)
*
* 通常是PHP的 $_SERVER 环境变量。
*
* @param bool $applyFilter
* @return array
*/
public function getServerParams()
public function getServerParams($applyFilter = true)
{
return $this->serverParams;
return $applyFilter ? $this->applyFilter($this->serverParams) : $this->serverParams;
}

/**
* 返回请求的Cookie信息
*
* @param bool $applyFilter
* @return array
*/
public function getCookieParams()
public function getCookieParams($applyFilter = true)
{
return $this->cookies;
return $applyFilter ? $this->applyFilter($this->cookies) : $this->cookies;
}

/**
Expand All @@ -370,18 +372,19 @@ public function withCookieParams(array $cookies)
/**
* 返回解码后的URL查询参数信息
*
* @param bool $applyFilter
* @return array
*/
public function getQueryParams()
public function getQueryParams($applyFilter = true)
{
if (is_array($this->queryParams)) {
return $this->queryParams;
return $applyFilter ? $this->applyFilter($this->queryParams) : $this->queryParams;
}
if ($this->uri === null) {
return [];
}
parse_str($this->uri->getQuery(), $this->queryParams);
return $this->queryParams;
return $applyFilter ? $this->applyFilter($this->queryParams) : $this->queryParams;
}

/**
Expand Down Expand Up @@ -424,11 +427,12 @@ public function withUploadedFiles(array $uploadedFiles)
/**
* 返回请求体
*
* @return null|array|object
* @param bool $applyFilter
* @return array|null|object
*/
public function getParsedBody()
public function getParsedBody($applyFilter = true)
{
return $this->parsedBody;
return $applyFilter ? $this->applyFilter($this->parsedBody) : $this->parsedBody;
}

/**
Expand All @@ -448,11 +452,12 @@ public function withParsedBody($data)
/**
* 返回从请求中解析出的属性信息
*
* @param bool $applyFilter
* @return array
*/
public function getAttributes()
public function getAttributes($applyFilter = true)
{
return $this->attributes;
return $applyFilter ? $this->applyFilter($this->attributes) : $this->attributes;
}

/**
Expand All @@ -461,14 +466,15 @@ public function getAttributes()
* @see getAttributes()
* @param string $name 属性名
* @param mixed $default 默认值
* @param bool $applyFilter
* @return mixed
*/
public function getAttribute($name, $default = null)
public function getAttribute($name, $default = null, $applyFilter = true)
{
if (false === array_key_exists($name, $this->attributes)) {
return $default;
}
return $this->attributes[$name];
return $applyFilter ? $this->applyFilter($this->attributes[$name]) : $this->attributes[$name];
}

/**
Expand Down Expand Up @@ -644,7 +650,7 @@ public function getServerParam($name, $default = null, $applyFilter = true)
*/
public function getQueryParam($name, $default = null, $applyFilter = true)
{
$getParams = $this->getQueryParams();
$getParams = $this->getQueryParams(false);
if (isset($getParams[$name])) {
return $applyFilter ? $this->applyFilter($getParams[$name]) : $getParams[$name];
}
Expand All @@ -661,7 +667,7 @@ public function getQueryParam($name, $default = null, $applyFilter = true)
*/
public function getPostParam($name, $default = null, $applyFilter = true)
{
$postParams = $this->getParsedBody();
$postParams = $this->getParsedBody(false);
if (isset($postParams[$name])) {
return $applyFilter ? $this->applyFilter($postParams[$name]) : $postParams[$name];
}
Expand Down

0 comments on commit d0d623d

Please sign in to comment.