mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Fixed bug that ValidationMiddleware
will throw exception in websocket. (#2139)
This commit is contained in:
parent
1855a666c9
commit
d3f14f740c
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user