Skip to content

Commit

Permalink
Stripping basePath from route url, only adding it when appropriate. F…
Browse files Browse the repository at this point in the history
…ixes #38 and #20.

Fixes #38 and #20.
  • Loading branch information
dannyvankooten committed Nov 8, 2013
1 parent 77e77de commit 01258d1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions AltoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public function setBasePath($basePath) {
*/
public function map($method, $route, $target, $name = null) {

if($route != '*') {
$route = $this->basePath . $route;
}

$this->routes[] = array($method, $route, $target, $name);

if($name) {
Expand Down Expand Up @@ -61,7 +57,9 @@ public function generate($routeName, array $params = array()) {

// Replace named parameters
$route = $this->namedRoutes[$routeName];
$url = $route;

// prepend base path to route url again
$url = $this->basePath . $route;

if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {

Expand Down Expand Up @@ -101,6 +99,9 @@ public function match($requestUrl = null, $requestMethod = null) {
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
}

// strip base path from request url
$requestUrl = substr($requestUrl, strlen($this->basePath));

// Strip query string (?a=b) from Request Url
if (($strpos = strpos($requestUrl, '?')) !== false) {
$requestUrl = substr($requestUrl, 0, $strpos);
Expand Down

0 comments on commit 01258d1

Please sign in to comment.