Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rpc Service 验证器使用报错 #1286

Closed
biiiiiigmonster opened this issue May 12, 2020 · 1 comment
Closed

Rpc Service 验证器使用报错 #1286

biiiiiigmonster opened this issue May 12, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@biiiiiigmonster
Copy link

Q A
Bug report? yes
Feature request? no
Swoft version 2.0.9
Swoole version 4.4.12
PHP version 7.4
Runtime environment Docker etc.

Describe the bug
RPC服务开启验证器使用时报错

Details

bean配置文件中配置RPC服务开启验证器

    'serviceDispatcher'    => [
        'afterMiddlewares' => [
            \Swoft\Rpc\Server\Middleware\ValidatorMiddleware::class
        ]
    ],

当使用验证器注解时,ValidatorMiddleware::class 第41行的 $request->getParamsMap()的实现中

namespace Swoft\Rpc\Server;

public function getParamsMap(): array
    {
        $rc       = BeanFactory::getReflection($this->interface);
        $rxParams = $rc['methods'][$this->method]['params'];

        $index     = 0;//此处index值锁定,导致$paramsMap无法正确获取$this->params
        $paramsMap = [];
        foreach ($rxParams as $methodParams) {
            if (!isset($this->params[$index])) {
                break;
            }

            [$name] = $methodParams;
            $paramsMap[$name] = $this->params[$index];
        }
        return $paramsMap;
    }

此处是否可以修改为

public function getParamsMap(): array
    {
        $rc       = BeanFactory::getReflection($this->interface);
        $rxParams = $rc['methods'][$this->method]['params'];

        //$index     = 0;
        $paramsMap = [];
        foreach ($rxParams as $index=>$methodParams) {
            if (!isset($this->params[$index])) {
                break;
            }

            [$name] = $methodParams;
            $paramsMap[$name] = $this->params[$index];
        }
        return $paramsMap;
    }
@github-actions github-actions bot added the swoft: validator issues for swoft validator component label May 12, 2020
@biiiiiigmonster
Copy link
Author

准确定位是rpc-server Request类的getParamsMap方法

@inhere inhere added this to the v2.0.10 milestone May 14, 2020
inhere added a commit to swoft-cloud/swoft-rpc-server that referenced this issue Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants