Skip to content

Commit

Permalink
Fixed route triggering with same path and different http methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiopvilar committed Aug 21, 2015
1 parent 26680f5 commit 7e625f7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private function addRoute($method, $parameters) {
$robj = [];
$route = $this->getPrefix($parameters[0]);
$robj['method'] = $method;
$robj['route'] = $route;
$robj['id'] = str_replace('=', '', base64_encode($method.$route));

$robj['callback'] = $parameters[count($parameters) -1];
Expand Down Expand Up @@ -173,6 +174,13 @@ private function getRoute($route_id) {
}
}

private function getRouteWithMethod($_route, $method) {
foreach($this->routes as $route) {
if($route['method'] == $method && $route['route'] == $_route['route'])
return $route;
}
}

private function getUrlParameters($params, $query_vars) {
$pars = [];
foreach($params as $param){
Expand Down Expand Up @@ -276,12 +284,15 @@ public function rewrite_url( $wp_rewrite ) {
}

public function parse_request($wp_query) {

if (isset($wp_query->query_vars['amp_route'])){

$route = $this->getRoute($wp_query->query_vars['amp_route']);
$_route = $this->getRouteWithMethod($route, $_SERVER['REQUEST_METHOD']);

if($route['id'] == $wp_query->query_vars['amp_route'] && $route['method'] == $_SERVER['REQUEST_METHOD']){
$this->getCallback($route, $wp_query->query_vars);
} else if($_route['method'] == $_SERVER['REQUEST_METHOD']) {
$this->getCallback($_route, $wp_query->query_vars);
} else {
Ampersand::getInstance()->response()->setStatus(404);
Ampersand::getInstance()->response()->template('404');
Expand Down

0 comments on commit 7e625f7

Please sign in to comment.