Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #62 . The generateRaw wasn't added to Router which makes it non us... #63

Merged
merged 1 commit into from Sep 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/Router.php
Expand Up @@ -175,17 +175,39 @@ public function getMatchedRoute()
* @return string|false A URI path string if the route name is found, or
* boolean false if not.
*
* @throw Exception\RouteNotFound
*
*/
public function generate($name, $data = array())
{
if (! $this->routes->offsetExists($name)) {
throw new Exception\RouteNotFound($name);
}
$this->routeExists($name);

$route = $this->routes->offsetGet($name);
return $this->generator->generate($route, $data);
}

/**
*
* Generate the route without url encoding.
*
* @param string $name The route name to look up.
*
* @param array $data The data to interpolate into the URI; data keys
* map to param tokens in the path.
*
* @return string|false A URI path string if the route name is found, or
* boolean false if not.
*
* @throw Exception\RouteNotFound
*
*/
public function generateRaw($name, $data = array())
{
$this->routeExists($name);
$route = $this->routes->offsetGet($name);
return $this->generator->generateRaw($route, $data);
}

/**
*
* Sets the array of route objects to use.
Expand Down Expand Up @@ -227,4 +249,11 @@ public function getDebug()
{
return $this->debug;
}

protected function routeExists($name)
{
if (! $this->routes->offsetExists($name)) {
throw new Exception\RouteNotFound($name);
}
}
}
13 changes: 13 additions & 0 deletions tests/unit/src/RouterTest.php
Expand Up @@ -465,4 +465,17 @@ public function testGetFailedRoute()
$failed_route = $this->router->getFailedRoute();
$this->assertSame($foo, $failed_route);
}

public function testGenerateRaw()
{
$this->router->add('asset', '/{vendor}/{package}/{file}');
$data = array(
'vendor' => 'vendor+name',
'package' => 'package+name',
'file' => 'foo/bar/baz.jpg',
);
$actual = $this->router->generateRaw('asset', $data);
$expect = '/vendor+name/package+name/foo/bar/baz.jpg';
$this->assertSame($actual, $expect);
}
}