0

有没有办法自动拥有一个 Guzzle Service Descriptor 字段,获取一个数组,并将其解析为逗号列表?

数据

Array [ "test", "another test" ]

服务描述符

{
    "name": "YouTube",
    "baseUrl": "https://www.googleapis.com",
    "apiVersion": "v3",
    "description": "YouTube GData Graph API",
    "operations": {
        "GetVideos": {
            "httpMethod": "GET",
            "uri": "/youtube/v3/videos",
            "parameters": {
                "id": {
                    "type":"array",
                    "location":"query",
                    "required": true
                },
                "part": {
                    "location": "query",
                    "default": "snippet"
                },
                "key": {
                    "location": "query",
                    "default": "{MY KEY}",
                    "static": true
                },
                "maxResults": {
                    "location": "query",
                    "default": 50
                }
            }

        }
    }
}

该字段是idunder parameters,我想为其提供原始的 php 字符串数组,并让 Guzzle 自动将其转换为逗号分隔的列表

现在,我必须这样做:

$command = $this->client->getCommand('GetVideos', [
    'id' => implode(",", array_slice($this->id, 0, 50))
]);

现在,这会创建一个包含多个 id 实例的 URL

https://www.googleapis.com/youtube/v3/videos?id=test&id=another%20test&part=snippet&key={MY KEY}&maxResults=50

我希望它像这样出来:

https://www.googleapis.com/youtube/v3/videos?id=test,another%20test&part=snippet&key={MY KEY}&maxResults=50

这可能吗?

4

1 回答 1

0

Guzzle 3 从Query具有聚合器的对象构造查询字符串。通过调用->setAggregator($aggregator)Query您可以覆盖默认行为。你想给它一个Guzzle\Http\QueryAggregator\CommaAggregator.

Guzzle 文档中没有太多关于它的内容,但有一个简短的提及

于 2014-07-24T17:26:54.077 回答