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

Added custom object support for controller parameters in http-server. #321

Merged
merged 15 commits into from Aug 4, 2019

Conversation

wenbinye
Copy link
Contributor

@wenbinye wenbinye commented Aug 2, 2019

这个修改为后面 jsonrpc-http 增加参数识别。同时也可以基于这个实现类似
spring mvc 中 @ModelAttribute 功能

这个修改为后面 jsonrpc-http 增加参数识别。同时也可以基于这个实现类似
spring mvc 中 @ModelAttribute 功能
@wenbinye wenbinye force-pushed the feature-http-parse-parameters branch from a61ec32 to f70b882 Compare August 2, 2019 03:45
@huangzhhui
Copy link
Member

@wenbinye 这个 PR 能提供一下供我测试的 Demo 吗?或者提供解决的场景

@wenbinye
Copy link
Contributor Author

wenbinye commented Aug 2, 2019

在 jsonrpc 有实际用途,目前 http 的参数都是从路由上得到,都是简单参数,用不上

@huangzhhui
Copy link
Member

在 jsonrpc 有实际用途,目前 http 的参数都是从路由上得到,都是简单参数,用不上

JSONRPC 上的用途场景可以描述一下吗?

@wenbinye
Copy link
Contributor Author

wenbinye commented Aug 2, 2019

以下面这个服务为例:

interface CalculatorServiceInterface
{
    /**
     * @param Integer[] $a
     * @return Integer
     */
    public function squareSum(array $a): Integer;
}

其中 Integer 类如下:

class Integer
{
    /**
     * @var int
     */
    public $value;
}

jsonrpc 传入的参数是:

[{"value":3},{"value":4}]

对于 CalculatorServiceInterface 的实现接收到的参数就是 Integer 类的示例构成的数组。
DocMethodDefinitionCollector 用于从方法的注解中读取参数类型,因为现在 php 的参数声明不能对对象数组声明类型,必须用注解方式。
SymfonySerializer 用于将数组类型的数据根据参数类型,转换成对应对象(denormalize)。
同时也提供对象根据属性和 getters 转换成数组(normalize)。

@limingxinleo limingxinleo changed the title http-server CoreMiddleware::parseParameters support complex parameters Added custom object support for controller parameters in http-server. Aug 4, 2019
Copy link
Member

@limingxinleo limingxinleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huangzhhui 有时间看一下,我这边觉得 OK 了。

composer.json Outdated Show resolved Hide resolved
src/di/src/ConfigProvider.php Outdated Show resolved Hide resolved
@limingxinleo limingxinleo merged commit cc6c245 into hyperf:master Aug 4, 2019
@wenbinye wenbinye deleted the feature-http-parse-parameters branch August 6, 2019 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants