Fixed bug that ValidationMiddleware will throw exception in websocket. (#2139)

This commit is contained in:
李铭昕 2020-07-20 11:40:32 +08:00 committed by GitHub
parent 1855a666c9
commit d3f14f740c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 12 deletions

View File

@ -11,6 +11,7 @@
- [#2017](https://github.com/hyperf/hyperf/pull/2017) Fixed when prometheus using the redis record, an error is reported during the rendering of data due to the change in the number of label.
- [#2117](https://github.com/hyperf/hyperf/pull/2117) Fixed `@Inject` will be useless sometimes when using `server:watch`.
- [#2123](https://github.com/hyperf/hyperf/pull/2123) Fixed bug that `redis::call` will be recorded twice.
- [#2139](https://github.com/hyperf/hyperf/pull/2139) Fixed bug that `ValidationMiddleware` will throw exception in websocket.
## Optimized

View File

@ -58,17 +58,19 @@ class ValidationMiddleware implements MiddlewareInterface
if ($this->shouldHandle($dispatched)) {
try {
[$requestHandler, $method] = $this->prepareHandler($dispatched->handler->callback);
$reflectionMethod = ReflectionManager::reflectMethod($requestHandler, $method);
$parameters = $reflectionMethod->getParameters();
foreach ($parameters as $parameter) {
if ($parameter->getType() === null) {
continue;
}
$classname = $parameter->getType()->getName();
if ($this->isImplementedValidatesWhenResolved($classname)) {
/** @var \Hyperf\Validation\Contract\ValidatesWhenResolved $formRequest */
$formRequest = $this->container->get($classname);
$formRequest->validateResolved();
if ($method) {
$reflectionMethod = ReflectionManager::reflectMethod($requestHandler, $method);
$parameters = $reflectionMethod->getParameters();
foreach ($parameters as $parameter) {
if ($parameter->getType() === null) {
continue;
}
$classname = $parameter->getType()->getName();
if ($this->isImplementedValidatesWhenResolved($classname)) {
/** @var \Hyperf\Validation\Contract\ValidatesWhenResolved $formRequest */
$formRequest = $this->container->get($classname);
$formRequest->validateResolved();
}
}
}
} catch (UnauthorizedException $exception) {
@ -114,7 +116,8 @@ class ValidationMiddleware implements MiddlewareInterface
if (strpos($handler, '@') !== false) {
return explode('@', $handler);
}
return explode('::', $handler);
$array = explode('::', $handler);
return [$array[0], $array[1] ?? null];
}
if (is_array($handler) && isset($handler[0], $handler[1])) {
return $handler;