[Router] Update the Url QueryString of the request object with the parameters return by the UrlMatcher to let the developer access thoses parameters

This commit is contained in:
Vincent Dieltiens 2013-11-09 01:02:01 +01:00 committed by Laurynas Veržukauskas
parent f2c67b3460
commit 74fb2a691b

View File

@ -3,6 +3,7 @@ namespace Ratchet\Http;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use Guzzle\Http\Message\RequestInterface; use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response; use Guzzle\Http\Message\Response;
use Guzzle\Http\Url;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@ -46,6 +47,16 @@ class Router implements HttpServerInterface {
throw new \UnexpectedValueException('All routes must implement Ratchet\Http\HttpServerInterface'); throw new \UnexpectedValueException('All routes must implement Ratchet\Http\HttpServerInterface');
} }
$parameters = array();
foreach($route as $key => $value) {
if (!in_array($key, array('_controller', '_route'))) {
$parameters[$key] = $value;
}
}
$url = Url::factory($request->getPath());
$url->setQuery($parameters);
$request->setUrl($url);
$conn->controller = $route['_controller']; $conn->controller = $route['_controller'];
$conn->controller->onOpen($conn, $request); $conn->controller->onOpen($conn, $request);
} }