Closed mtdowling closed 10 years ago
@mtdowling
hmm... Sounds interesting, but i'm sure it's something proprietary. There are a lot of issues with nested arrays of arrays(or objects):
Current implementation is in tact with spec which doesn't define similar features. URI templates are not local to PHP and thus i'd prefer to ignore such proprietary things. Furthermore, what should be expected result of this:
echo uri_template('http://foo!{foo*}', array(
'foo' => array(
'baz' => array(
'bar' => (object) array(
'prop1' => array(1, 2, array('key1' => 'foo bar prop1', 17), 4),
'prop2' => null
)
)
)
));
Here is a uritemplate-test project which is maintained by URI Template spec authors. All of tests are already integrated in Pecl URI Template extension and none of these tests contain such nested structures. I'd be happy to move this discussion further, we can ask spec authors regarding this.
@mtdowling i'm closing this ticket, we can reopen it if need be.
Just out of curiosity how is this "proprietary"? The request is for the same functionality that http_build_query() provides. Is it proprietary only to php? or... I believe other languages do this as well...
Example #3 http_build_query() with complex arrays
<?php
$data = array('user'=>array('name'=>'Bob Smith',
'age'=>47,
'sex'=>'M',
'dob'=>'5/12/1956'),
'pastimes'=>array('golf', 'opera', 'poker', 'rap'),
'children'=>array('bobby'=>array('age'=>12,
'sex'=>'M'),
'sally'=>array('age'=>8,
'sex'=>'F')),
'CEO');
echo http_build_query($data, 'flags_');
?>
this will output : (word wrapped for readability)
user%5Bname%5D=Bob+Smith&user%5Bage%5D=47&user%5Bsex%5D=M& user%5Bdob%5D=5%2F12%2F1956&pastimes%5B0%5D=golf&pastimes%5B1%5D=opera& pastimes%5B2%5D=poker&pastimes%5B3%5D=rap&children%5Bbobby%5D%5Bage%5D=12& children%5Bbobby%5D%5Bsex%5D=M&children%5Bsally%5D%5Bage%5D=8& children%5Bsally%5D%5Bsex%5D=F&flags_0=CEO
@webdobe Maybe this(or similar) behaviour is implemented in another languages, these are not defined by IETF RFCs(do not confuse with PHP RFCs). URI Template extension implements IETF RFC-6570 that also depends on IETF RFC-3986. I do believe implementation should conform to these specs despite the fact that it is implemented for PHP.
P.S. URI encoded by http_build_query(...) won't be parsed as a nested associative array in other platforms.
It looks like adding nested arrays with * variable expansion will throw a notice and convert the expansion to 'Array':
I would expect this to use PHP's query string formatting to output the following:
http://foo!baz%5Bbar%5D=123
That's the current behavior of Guzzle's URI template expansion: https://github.com/guzzle/guzzle/issues/90