Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Implement query and fragment assembling into the HTTP router itself #3794

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/Zend/Mvc/Router/Http/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Query route.
*
* @see http://guides.rubyonrails.org/routing.html
* @deprecated
*/
class Query implements RouteInterface
{
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Mvc/Router/Http/TreeRouteStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ public function assemble(array $params = array(), array $options = array())

$path = $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);

if (isset($options['query'])) {
$uri->setQuery($options['query']);
}

if (isset($options['fragment'])) {
$uri->setFragment($options['fragment']);
}

if ((isset($options['force_canonical']) && $options['force_canonical']) || $uri->getHost() !== null) {
if ($uri->getScheme() === null) {
if ($this->requestUri === null) {
Expand Down
32 changes: 32 additions & 0 deletions tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ public function testAssembleWithQueryRoute()
$this->assertEquals('/?bar=baz', $stack->assemble(array('bar' => 'baz'), array('name' => 'index/query')));
}

public function testAssembleWithQueryParams()
{
$stack = new TreeRouteStack();
$stack->addRoute(
'index',
array(
'type' => 'Literal',
'options' => array(
'route' => '/',
),
)
);

$this->assertEquals('/?foo=bar', $stack->assemble(array(), array('name' => 'index', 'query' => array('foo' => 'bar'))));
}

public function testAssembleWithFragment()
{
$stack = new TreeRouteStack();
$stack->addRoute(
'index',
array(
'type' => 'Literal',
'options' => array(
'route' => '/',
),
)
);

$this->assertEquals('/#foobar', $stack->assemble(array(), array('name' => 'index', 'fragment' => 'foobar')));
}

public function testAssembleWithoutNameOption()
{
$this->setExpectedException('Zend\Mvc\Router\Exception\InvalidArgumentException', 'Missing "name" option');
Expand Down