vlucas / bulletphp

A resource-oriented micro PHP framework
http://bulletphp.com
BSD 3-Clause "New" or "Revised" License
418 stars 50 forks source link

Query params available from $app->param('key') but not $app->query('key') #63

Closed acicali closed 9 years ago

acicali commented 9 years ago

Is this the expected behavior and the documentation is just outdated? ... or am I missing something obvious?

This is all I'm doing:

$app = new Bullet\App();

$app->path('test', function($request) use($app){
    return $request->query('foo'); // outputs "OK"
    // return $request->param('foo'); /* outputs value of $_GET['foo'], e.g. "bar" */
    // die(var_dump($request));
});

echo $app->run(new Bullet\Request());

And the URL:

/test?foo=bar

Here's a var_dump() of the request object:

object(Bullet\Request)#12 (10) {
  ["_method":protected]=>
  string(3) "GET"
  ["_url":protected]=>
  string(5) "/test"
  ["_format":protected]=>
  string(4) "html"
  ["_headers":protected]=>
  array(30) {
    ["USER"]=>
    string(5) "nginx"
    ["HOME"]=>
    string(14) "/var/lib/nginx"
    ["FCGI_ROLE"]=>
    string(9) "RESPONDER"
    ["QUERY_STRING"]=>
    string(0) ""
    ["REQUEST_METHOD"]=>
    string(3) "GET"
    ["CONTENT_TYPE"]=>
    string(0) ""
    ["CONTENT_LENGTH"]=>
    string(0) ""
    ["SCRIPT_NAME"]=>
    string(10) "/index.php"
    ["REQUEST_URI"]=>
    string(13) "/test?foo=bar"
    ["DOCUMENT_URI"]=>
    string(10) "/index.php"
    ["DOCUMENT_ROOT"]=>
    string(22) "/var/www/bullet/public"
    ["SERVER_PROTOCOL"]=>
    string(8) "HTTP/1.1"
    ["GATEWAY_INTERFACE"]=>
    string(7) "CGI/1.1"
    ["SERVER_SOFTWARE"]=>
    string(12) "nginx/1.0.15"
    ["REMOTE_ADDR"]=>
    string(12) "192.168.56.1"
    ["REMOTE_PORT"]=>
    string(5) "52223"
    ["SERVER_ADDR"]=>
    string(13) "192.168.56.25"
    ["SERVER_PORT"]=>
    string(2) "80"
    ["SERVER_NAME"]=>
    string(6) "bullet"
    ["SCRIPT_FILENAME"]=>
    string(32) "/var/www/bullet/public/index.php"
    ["REDIRECT_STATUS"]=>
    string(3) "200"
    ["HTTP_HOST"]=>
    string(6) "bullet"
    ["HTTP_CONNECTION"]=>
    string(10) "keep-alive"
    ["HTTP_ACCEPT"]=>
    string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
    ["HTTP_USER_AGENT"]=>
    string(109) "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36"
    ["HTTP_ACCEPT_ENCODING"]=>
    string(17) "gzip,deflate,sdch"
    ["HTTP_ACCEPT_LANGUAGE"]=>
    string(14) "en-US,en;q=0.8"
    ["PHP_SELF"]=>
    string(10) "/index.php"
    ["REQUEST_TIME_FLOAT"]=>
    float(1414093153.1291)
    ["REQUEST_TIME"]=>
    int(1414093153)
  }
  ["_params":protected]=>
  array(1) {
    ["foo"]=>
    string(3) "bar"
  }
  ["_postParams":protected]=>
  array(0) {
  }
  ["_queryParams":protected]=>
  array(0) {
  }
  ["_accept":protected]=>
  array(5) {
    ["text/html"]=>
    string(9) "text/html"
    ["application/xhtml+xml"]=>
    string(21) "application/xhtml+xml"
    ["image/webp"]=>
    string(10) "image/webp"
    ["application/xml"]=>
    string(15) "application/xml"
    ["*/*"]=>
    string(3) "*/*"
  }
  ["_raw":protected]=>
  NULL
  ["_mimeTypes":protected]=>
  array(22) {
    ["txt"]=>
    string(10) "text/plain"
    ["html"]=>
    string(9) "text/html"
    ["xhtml"]=>
    string(21) "application/xhtml+xml"
    ["xml"]=>
    string(15) "application/xml"
    ["css"]=>
    string(8) "text/css"
    ["js"]=>
    string(22) "application/javascript"
    ["json"]=>
    string(16) "application/json"
    ["csv"]=>
    string(8) "text/csv"
    ["png"]=>
    string(9) "image/png"
    ["jpe"]=>
    string(10) "image/jpeg"
    ["jpeg"]=>
    string(10) "image/jpeg"
    ["jpg"]=>
    string(10) "image/jpeg"
    ["gif"]=>
    string(9) "image/gif"
    ["bmp"]=>
    string(9) "image/bmp"
    ["ico"]=>
    string(24) "image/vnd.microsoft.icon"
    ["tiff"]=>
    string(10) "image/tiff"
    ["tif"]=>
    string(10) "image/tiff"
    ["svg"]=>
    string(13) "image/svg+xml"
    ["svgz"]=>
    string(13) "image/svg+xml"
    ["zip"]=>
    string(15) "application/zip"
    ["rar"]=>
    string(28) "application/x-rar-compressed"
    ["pdf"]=>
    string(15) "application/pdf"
  }
}

Thank you.

vlucas commented 9 years ago

This may simply have to do with the way nginx is configured. Most configurations should be set to append query string variables to the rewrite request. If they don't, Bullet may not see them as variables in the query string (i.e. if you var_dump($_GET) that is probably empty too).

Your configuration gives it away here:

    ["QUERY_STRING"]=>
    string(0) ""
    ...
    ["REQUEST_URI"]=>
    string(13) "/test?foo=bar"

You should be able to solve this by adding index.php?$args to your try_files line.

acicali commented 9 years ago

Doh! Sorry for that, thanks for doing my homework!

vlucas commented 9 years ago

No problem. I should probably whip up some docs on deployment :)