Permalink
Browse files

Merge branch 'rszrama-issue-1316' into develop

Closes #1316
Closes #1320
  • Loading branch information...
2 parents 2afbe5e + 2db013e commit 1c80f1aeb09b54ff999d7049ab339facb02d4d82 @akrabat akrabat committed Jun 28, 2015
Showing with 39 additions and 20 deletions.
  1. +3 −3 Slim/Interfaces/RouterInterface.php
  2. +24 −5 Slim/Router.php
  3. +12 −12 tests/RouterTest.php
@@ -57,15 +57,15 @@ public function pushGroup($group, $middleware = []);
public function popGroup();
/**
- * Build URL for named route
+ * Build the path for a named route
*
* @param string $name Route name
- * @param array $data Route URI segments replacement data
+ * @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @return string
* @throws \RuntimeException If named route does not exist
* @throws \InvalidArgumentException If required data not provided
*/
- public function urlFor($name, array $data = [], array $queryParams = []);
+ public function pathFor($name, array $data = [], array $queryParams = []);
}
View
@@ -167,17 +167,17 @@ public function popGroup()
}
/**
- * Build URL for named route
+ * Build the path for a named route
*
- * @param string $name Route name
- * @param array $data Route URI segments replacement data
- * @param array $queryParams Optional query string parameters
+ * @param string $name Route name
+ * @param array $data Named argument replacement data
+ * @param array $queryParams Optional query string parameters
*
* @return string
* @throws \RuntimeException If named route does not exist
* @throws \InvalidArgumentException If required data not provided
*/
- public function urlFor($name, array $data = [], array $queryParams = [])
+ public function pathFor($name, array $data = [], array $queryParams = [])
{
if (is_null($this->namedRoutes)) {
$this->buildNameIndex();
@@ -235,6 +235,25 @@ public function urlFor($name, array $data = [], array $queryParams = [])
}
/**
+ * Build the path for a named route.
+ *
+ * This method is deprecated. Use pathFor() from now on.
+ *
+ * @param string $name Route name
+ * @param array $data Named argument replacement data
+ * @param array $queryParams Optional query string parameters
+ *
+ * @return string
+ * @throws \RuntimeException If named route does not exist
+ * @throws \InvalidArgumentException If required data not provided
+ */
+ public function urlFor($name, array $data = [], array $queryParams = [])
+ {
+ trigger_error('urlFor() is deprecated. Use pathFor() instead.', E_USER_DEPRECATED);
+ return $this->pathFor($name, $data, $queryParams);
+ }
+
+ /**
* Build index of named routes
*/
protected function buildNameIndex()
View
@@ -67,7 +67,7 @@ public function testMapPrependsGroupPattern()
$this->assertAttributeEquals('/prefix/hello/{first}/{last}', 'pattern', $route);
}
- public function testUrlFor()
+ public function testPathFor()
{
$methods = ['GET'];
$pattern = '/hello/{first:\w+}/{last}';
@@ -79,11 +79,11 @@ public function testUrlFor()
$this->assertEquals(
'/hello/josh/lockhart',
- $this->router->urlFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
+ $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])
);
}
- public function testUrlForWithOptionalParameters()
+ public function testPathForWithOptionalParameters()
{
$methods = ['GET'];
$pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]';
@@ -95,19 +95,19 @@ public function testUrlForWithOptionalParameters()
$this->assertEquals(
'/archive/2015',
- $this->router->urlFor('foo', ['year' => '2015'])
+ $this->router->pathFor('foo', ['year' => '2015'])
);
$this->assertEquals(
'/archive/2015/07',
- $this->router->urlFor('foo', ['year' => '2015', 'month' => '07'])
+ $this->router->pathFor('foo', ['year' => '2015', 'month' => '07'])
);
$this->assertEquals(
'/archive/2015/07/d/19',
- $this->router->urlFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19'])
+ $this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19'])
);
}
- public function testUrlForWithQueryParameters()
+ public function testPathForWithQueryParameters()
{
$methods = ['GET'];
$pattern = '/hello/{name}';
@@ -119,14 +119,14 @@ public function testUrlForWithQueryParameters()
$this->assertEquals(
'/hello/josh?a=b&c=d',
- $this->router->urlFor('foo', ['name' => 'josh'], ['a' => 'b', 'c' => 'd'])
+ $this->router->pathFor('foo', ['name' => 'josh'], ['a' => 'b', 'c' => 'd'])
);
}
/**
* @expectedException \InvalidArgumentException
*/
- public function testUrlForWithMissingSegmentData()
+ public function testPathForWithMissingSegmentData()
{
$methods = ['GET'];
$pattern = '/hello/{first}/{last}';
@@ -136,13 +136,13 @@ public function testUrlForWithMissingSegmentData()
$route = $this->router->map($methods, $pattern, $callable);
$route->setName('foo');
- $this->router->urlFor('foo', ['last' => 'lockhart']);
+ $this->router->pathFor('foo', ['last' => 'lockhart']);
}
/**
* @expectedException \RuntimeException
*/
- public function testUrlForRouteNotExists()
+ public function testPathForRouteNotExists()
{
$methods = ['GET'];
$pattern = '/hello/{first}/{last}';
@@ -152,6 +152,6 @@ public function testUrlForRouteNotExists()
$route = $this->router->map($methods, $pattern, $callable);
$route->setName('foo');
- $this->router->urlFor('bar', ['first' => 'josh', 'last' => 'lockhart']);
+ $this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']);
}
}

0 comments on commit 1c80f1a

Please sign in to comment.