Repository navigation
UrlMap not interpreting REQUEST_URI correctly #9
Description
Activity
Tested it on the dev server, works for me.
app_dev.php:<?php require "vendor/autoload.php"; use Stack\CallableHttpKernel; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $app = new CallableHttpKernel(function ($req) { return new Response("app"); }); $foo = new CallableHttpKernel(function ($req) { return new Response("foo"); }); $map = new Stack\UrlMap($app, [ '/foo' => $foo ]); $resp = $map->handle(Request::createFromGlobals()); $resp->send();
On the shell:
$ php -S localhost:4000 -t ./Request in the browser: http://localhost:4000/app_dev.php/foo and you should get "foo"
Make sure that you request this code really through
app_dev.php. It doesn't work ifapp_dev.phpis not a real script and the "app_dev.php" is not the basename of the script filename. We can't do anything about this, it's all handled internally by the request object.Your example works correctly, but I invite you to try it with Stack\Builder and a fresh Symfony install.
There's either a problem, or the documentation isn't clear enough on how to handle this.
Ok, looking into it.
Am Dienstag, 13. August 2013 schrieb Jarrod Nettles :
Your example works, but I invite you to try it with Stack\Builder and a
fresh Symfony install.There's either a problem, or the documentation isn't clear enough on how
to handle this.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-22580791
.Christoph Hochstrasser
http://twitter.com/yuri41 | http://christophh.net | https://github.com/CHHRe-opening, just so this does not get lost.
I had to use it today and I confirm that the issue exists. In my app, when i access site via app_dev.php,
i had to change server variables in handle to make it work with app_dev.php to:$server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'] = $server['PHP_SELF'] = $server['SCRIPT_NAME'] . $path;
cc @Blackshawk
@defrag Could you please post the complete file with your code?
@Blackshawk:
I've now tried it with Symfony 2.3 Components and Stack Builder and it works without problems on the builtin dev server.What web server are you using?
Here is my code:
<?php require "vendor/autoload.php"; use Stack\CallableHttpKernel; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Stack\UrlMap; use Stack\Builder; $app = new CallableHttpKernel(function ($req) { return new Response("app"); }); $foo = new CallableHttpKernel(function ($req) { echo "<pre>"; print_r($_SERVER); echo "</pre>"; return new Response("foo"); }); $app = (new Builder) ->push(UrlMap::class, [ '/foo' => $foo ]) ->resolve($app); $resp = $app->handle(Request::createFromGlobals()); $resp->send();
@Blackshawk: Will try it with a fresh Symfony install too.
@Blackshawk: Tried it with a completely fresh Symfony 2.3 install and it works with
./app/console server:run.I added only this to my
app_dev.php:<?php $kernel = (new Stack\Builder) ->push(Stack\UrlMap::class, [ '/foo' => new Stack\CallableHttpKernel(function ($req) { return new Response("foo"); }) ]) ->resolve($kernel);
@defrag @Blackshawk Which web server gives you this issues? Apache, NGINX or the builtin dev server?
@CHH Well it will work with the CallableHttpKernel with simple response like you showed, but it will not work with symfony2 app kernel. In my case I have FeatureKernel that extends AppKernel, which have some associated webservices that needs to be mock per feature.
foreach ($fakeWs as $key => $value) { $map['/' . $key] = $featureKernel; } $stack = (new Stack\Builder) ->push('Stack\UrlMap', $map) ;
Then im accessing page like app_dev.php/FEATURE-123/ and it boots kernel with needed data.
If i will not change the server variables like I mentioned in sample before, all routings etc will totally mess. Try mapping new AppKernel instead of CallableHttpKernel and You will see errors.
Hope that explanation helps. I didnt found the best way to handle this yet, im currently using modified UrlMap.Have the same problem with lighttpd and fpm.
In situations where there is a file prefix in the REQUEST_URI, UrlMap incorrectly includes it as part of the intended route.
For example, in Symfony during development, you usually visit the app through
local.dev/app_dev.php/my/actionand Symfony is smart enough to compute the /my/action route automatically, chopping off the app_dev.php.StackPHP does not chop off this file prefix. It seems to me that this should be the expected behavior.
You can easily reproduce this issue by using two middlewares and UrlMap through a file in the URL.