Added method Hyperf\HttpServer\Request::clearStoredParsedData(). (#3514)

* Added method `Hyperf\HttpServer\Request::clearStoredParsedData()`.

* Added test cases

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
upper1027 2021-04-22 16:11:01 +08:00 committed by GitHub
parent 4be1f519cd
commit 6cea3ce4de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,10 @@
- [#3510](https://github.com/hyperf/hyperf/pull/3510) Fixed bug that consult couldn't force a node into the left state.
- [#3513](https://github.com/hyperf/hyperf/pull/3513) Fixed nats connection closed accidentally when socket timeout is smaller than max idle time.
## Added
- [#3514](https://github.com/hyperf/hyperf/pull/3514) Added method `Hyperf\HttpServer\Request::clearStoredParsedData()`.
# v2.1.15 - 2021-04-19
## Added

View File

@ -503,6 +503,13 @@ class Request implements RequestInterface
return $this->call(__FUNCTION__, func_get_args());
}
public function clearStoredParsedData(): void
{
if (Context::has($this->contextkeys['parsedData'])) {
Context::set($this->contextkeys['parsedData'], null);
}
}
/**
* Check that the given file is a valid SplFileInfo instance.
* @param mixed $file

View File

@ -94,4 +94,21 @@ class RequestTest extends TestCase
$psrRequest = new Request();
$this->assertSame(['id' => 1, 'name' => 'Hyperf'], $psrRequest->inputs(['id', 'name'], ['name' => 'Hyperf']));
}
public function testClearStoredParsedData()
{
$psrRequest = new \Hyperf\HttpMessage\Server\Request('GET', '/');
$psrRequest = $psrRequest->withParsedBody(['id' => 1]);
Context::set(ServerRequestInterface::class, $psrRequest);
$request = new Request();
$this->assertSame(['id' => 1], $request->all());
$psrRequest = $psrRequest->withParsedBody(['id' => 1, 'name' => 'hyperf']);
Context::set(ServerRequestInterface::class, $psrRequest);
$this->assertSame(['id' => 1], $request->all());
$request->clearStoredParsedData();
$this->assertSame(['id' => 1, 'name' => 'hyperf'], $request->all());
}
}