Skip to content

Validator增加Json格式支持#122

Merged
huangzhhui merged 3 commits intoswoft-cloud:masterfrom
limingxinleo:features/validator-json-support
Jul 12, 2018
Merged

Validator增加Json格式支持#122
huangzhhui merged 3 commits intoswoft-cloud:masterfrom
limingxinleo:features/validator-json-support

Conversation

@limingxinleo
Copy link
Contributor

No description provided.

@huangzhhui
Copy link
Contributor

Json不是一种参数类型,不应该与Get Post同等吧

@limingxinleo
Copy link
Contributor Author

就算不等同,也应该有办法检测一下吧。。。我们公司这边POST全部都是json的,这样一来,就没办法使用HttpValidator了。。。

@huangzhhui
Copy link
Contributor

这个直接改一下参数提供的部分就好了,Content-Type为json情况下,提供对应的数据参数

@limingxinleo
Copy link
Contributor Author

@huangzhhui 能具体说明一下么。。不是很明白

@huangzhhui
Copy link
Contributor

在POST模式下,如果 Content-Typeapplication/json 则取 $request->json() 而不是 $request->getParsedBody() 即可

@huangzhhui
Copy link
Contributor

huangzhhui commented Jul 11, 2018

增加Json层级数据验证

    /**
     * @RequestMapping("string")
     *
     * @Strings(from=ValidatorFrom::POST, name="user.name", min=3, max=10, default="Tom")
     * @Strings(from=ValidatorFrom::POST, name="text", min=3, max=11, default="text")
     *
     * @param string  $name
     * @param Request $request
     *
     * @return array
     */
    public function string(Request $request, string $name)
    {
        return [
            $request->json('user.name'),
            $request->json('text'),
        ];
    }

Request Body:

{
	"user": {
		"name": "Swoft"
	},
	"text": "This's text"
}

@limingxinleo
Copy link
Contributor Author

👍

@huangzhhui huangzhhui merged commit f65131a into swoft-cloud:master Jul 12, 2018
@huangzhhui huangzhhui changed the title 增加Json Validator支持 Validator增加Json格式支持 Jul 12, 2018
@limingxinleo limingxinleo deleted the features/validator-json-support branch July 13, 2018 04:21
huangzhhui pushed a commit to swoft-cloud/swoft-http-message that referenced this pull request Jul 15, 2018
* 增加Json Validator支持
* 当content-type为json时,重置$post的数据,进行验证
* get json value by dot notation for validator
huangzhhui pushed a commit to swoft-cloud/swoft-http-server that referenced this pull request Jul 15, 2018
* 增加Json Validator支持
* 当content-type为json时,重置$post的数据,进行验证
* get json value by dot notation for validator
huangzhhui added a commit that referenced this pull request Aug 8, 2018
4b3176b2 Upstream travis ci config (#160)
42be799f 修复Json Validator会失效的BUG (#153)
d1db1cf1 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)
649e67a4 Validator增加Json格式支持 (#122)

git-subtree-dir: src/http-server
git-subtree-split: 4b3176b2d43dba4a3f7db5ad754c017ab1d8d294
swoft-bot added a commit that referenced this pull request Oct 15, 2018
218abf7 Update Request.php (#184)
b20adb8 修复Json Validator会失效的BUG (#153)
68b8332 fix stripos() expects parameter 1 to be string, array given (#140)
31e4eb9 fix: cannot correctly detect json request (#135)
6be72b3 Validator增加Json格式支持 (#122)
c9e871d  add coWrite(); use swoft/swoole-ide-helper (#83)
c989bfe add server params

git-subtree-dir: src/http-message
git-subtree-split: 218abf7ed6ecc16ae7ba3a3d61e1fc6d67caa1b9
swoft-bot pushed a commit to swoft-cloud/swoft-view that referenced this pull request Jan 25, 2019
* 增加Json Validator支持
* 当content-type为json时,重置$post的数据,进行验证
* get json value by dot notation for validator
stelin pushed a commit to swoft-cloud/swoft-http-message that referenced this pull request May 28, 2019
* 增加Json Validator支持
* 当content-type为json时,重置$post的数据,进行验证
* get json value by dot notation for validator
stelin pushed a commit to swoft-cloud/swoft-http-server that referenced this pull request May 28, 2019
* 增加Json Validator支持
* 当content-type为json时,重置$post的数据,进行验证
* get json value by dot notation for validator
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.

2 participants