Skip to content

Commit

Permalink
Merge pull request #16 from alterfw/add-ignore-method
Browse files Browse the repository at this point in the history
Creates Route::ignore method to skip a route
  • Loading branch information
sergiopvilar committed Nov 20, 2019
2 parents 37c5c9b + 5e1a933 commit e5f91a9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Route {

private $routes = [];
private $ignoredRoutes = [];
private $root = false;
private $base = '';
private static $routeInstance;
Expand Down Expand Up @@ -39,6 +40,10 @@ public static function group() {
self::instance()->addGroup(func_get_args());
}

public static function ignore($path) {
self::instance()->ignoreRoute($path);
}

public static function get(){
self::instance()->addRoute('GET', func_get_args());
}
Expand Down Expand Up @@ -117,6 +122,10 @@ private function addGroup($parameters) {

}

private function ignoreRoute($path) {
array_push($this->ignoredRoutes, $path);
}

private function addRoute($method, $parameters) {

$methods = (is_array($method)) ? $method : [$method];
Expand Down Expand Up @@ -265,6 +274,7 @@ public function parse_request() {
}
$uri = rawurldecode($uri);

if(in_array($uri, $this->ignoredRoutes)) return;
if(strpos($uri, '/wp-admin') > -1) return;

if($uri == '/404' || $uri == '/404/')
Expand Down

0 comments on commit e5f91a9

Please sign in to comment.