-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
484badd
commit c487fd6
Showing
2 changed files
with
7 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,9 @@ | ||
<?php | ||
|
||
namespace Makaroni\Core\Route; | ||
|
||
use Symfony\Component\Routing\Matcher\UrlMatcher; | ||
use Symfony\Component\Routing\RequestContext; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
use AlirezaSalehizadeh\Routail\Router as Routail; | ||
|
||
class Router | ||
class Router extends Routail | ||
{ | ||
|
||
private static $router; | ||
|
||
private static $routes; | ||
|
||
private function __construct() | ||
{ | ||
static::$routes = new RouteCollection(); | ||
|
||
} | ||
|
||
public static function getInstance(): object { | ||
if(self::$router == null) { | ||
$router=self::$router = new Router(); | ||
} | ||
return $router; | ||
} | ||
|
||
|
||
public function add(string $path, array $defaults, string $name): void | ||
{ | ||
$route = new Route($path, ['controller' => $defaults[0], 'method' => $defaults[1]]); | ||
static::$routes->add($name, $route); | ||
|
||
} | ||
|
||
public function load(string $routeFilePath): object | ||
{ | ||
require_once $routeFilePath; | ||
return $this; | ||
} | ||
|
||
public function find(string $pathinfo): array | ||
{ | ||
$context = new RequestContext(); | ||
$matcher = new UrlMatcher(static::$routes, $context); | ||
return $matcher->match($pathinfo); | ||
} | ||
} | ||
} |