Skip to content

Commit

Permalink
Moved root route logit to parse_request() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiopvilar committed Aug 18, 2015
1 parent 94ebf10 commit 1a429f8
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@ private function __construct(){
$this->registerFilters();
}

public function __destruct() {

if($this->getEnv() == 'WP') {
$url = "http" . (($_SERVER['SERVER_PORT'] == 443) ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if($this->root && str_replace($this->base, '', $url) == '/'){
$route = $this->getRoute($this->root);
$this->getCallback($route, []);
Ampersand::getInstance()->run();
$this->end();
}
}

}

public function setRoutes($r) {
$this->routes = $r;
}
Expand Down Expand Up @@ -292,6 +278,7 @@ 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']);
if($route['id'] == $wp_query->query_vars['amp_route'] && $route['method'] == $_SERVER['REQUEST_METHOD']){
$this->getCallback($route, $wp_query->query_vars);
Expand All @@ -303,7 +290,19 @@ public function parse_request($wp_query) {
Ampersand::getInstance()->run();
$this->end();

} else {

if($this->getEnv() == 'WP') {
$url = "http" . (($_SERVER['SERVER_PORT'] == 443) ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if($this->root && str_replace($this->base, '', $url) == '/'){
$route = $this->getRoute($this->root);
$this->getCallback($route, []);
Ampersand::getInstance()->run();
}
}

}

}

}

0 comments on commit 1a429f8

Please sign in to comment.