Skip to content
Advertisement

Guzzle Service Description How to have Comma Deliminated Array?

is there a way to automatically have a Guzzle Service Descriptor field, take an array, and it’ll parse it to a comma list?

Data

Array [ "test", "another test" ]

Service Descriptors

JavaScript

The field is the id under parameters, I’d like to provide the raw php array of strings to that, and have Guzzle automatically convert that to a comma deliminated list

Right now, I have to do this:

JavaScript

Right now, that creates a URL with multiple instances of id

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

and I want it to come out like:

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

Is this possible?

Advertisement

Answer

Guzzle 3 constructs querystrings from a Query object, which has an aggregator. By calling ->setAggregator($aggregator) on the Query, you can override the default behavior. You want to give it an instance of GuzzleHttpQueryAggregatorCommaAggregator.

There isn’t much in the Guzzle docs about it, but there is a brief mention.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement