handling querystrings like foo[]=bar&foo[]=baz without turning them into foo[0]=bar&foo[1]=baz in 3.7

21 views
Skip to first unread message

ryr...@gmail.com

unread,
Jun 25, 2014, 6:35:25 PM6/25/14
to guz...@googlegroups.com
I'm using Guzzle 3.7. I have been reading and it seems this problem is fixed in 4.x but unfortunately that's not an option for me since I need to deploy on PHP 5.3, and 4.x requires PHP 5.4. I also tried to take some cues from the 4.x code but it looks like most of it has been rewritten from the ground up.

Basically I am constructing an array like this:

    $p = array(
      'filters' => array(
        'status' => array(
          'IN_PROGRESS',
          'RECEIVED'
        ),
        'limit' => 10
      )
    );

And I need the resulting querystring Guzzle sends to look like this:

?filters[status][]=IN_PROGRESS&filters[status][]=RECEIVED&limit=10

But, it's inserting numerical keys in each array index:

?filters[status][0]=IN_PROGRESS&filters[status][1]=RECEIVED&page=1&limit=10

What's the best solution to this problem for Guzzle 3.7? I've tried overriding various classes and making my own QueryAggregator but couldn't pull it off, I may have done something wrong but it seems like no matter what the data is always stored as an array in the QueryString and will always have that numerical index. Is there a way to pass the querystring as an explicit string and force Guzzle to use it instead of converting it to an array and back to a string?
Reply all
Reply to author
Forward
0 new messages