technically-php / rack-utils-http-query
Tiny package to build HTTP URL query string compatible with Rails apps
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/technically-php/rack-utils-http-query
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: 3.*|4.*|5.*
This package is not auto-updated.
Last update: 2025-02-06 07:28:59 UTC
README
Tiny package to build HTTP URL query string compatible with Rails app.
Usage
This library produces output without explicit indices. As simple as that.
$vars = ['fruits' => ['apple', 'banana', 'orange']]; $query_string = \TechnicallyPhp\RackUtilsHttpQuery::build($vars); var_dump($query_string); // will output: "fruits[]=apple&fruits[]=banana&fruits[]=orange"
Motivation
PHP stock http_build_query()
converts array into items with indices explicitly defined.
This is not compatible with the way Rails applications parse requests.
$vars = ['fruits' => ['apple', 'banana', 'orange']]; $query_string = http_build_query($vars); var_dump($query_string); // will output: "fruits[0]=apple&fruits[1]=banana&fruits[2]=orange"
Relevant StackOverflow discussions:
Details
This package follows
Rack::Utils.parse_nested_query
specification.
Please check RackUtilsHttpQueryTest.php.