diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-10-25 20:25:05 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-10-25 20:25:05 +0200 |
commit | a91c916248f967da2d4218b575e665242b7c975b (patch) | |
tree | 3c767e9b7b62161253aef2d93030f4b38fd47d49 /w/class/router.php | |
parent | 7b2e48276b2a3ceff83c906d38077f8d0479c3df (diff) | |
download | wcms-a91c916248f967da2d4218b575e665242b7c975b.tar.gz wcms-a91c916248f967da2d4218b575e665242b7c975b.zip |
phoenixreborn\'NWY
Diffstat (limited to 'w/class/router.php')
-rw-r--r-- | w/class/router.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/w/class/router.php b/w/class/router.php new file mode 100644 index 0000000..4d9d718 --- /dev/null +++ b/w/class/router.php @@ -0,0 +1,63 @@ +<?php + + +class Router +{ + protected $route; + + const ROUTES = [ + 'art' => ['art', 'read'], + 'art aff=read' => ['art', 'read'], + 'art aff=edit' => ['art', 'edit'], + 'art action=update home' => ['art', 'update', 'home'], + 'art action=add' => ['art', 'add'], + 'art action=delete' => ['art', 'delete'], + 'aff=home action=massedit', + 'aff=home' => ['home', 'desktop'], + '' => ['home', 'desktop'], + 'aff=home action=massedit' => ['home', 'massedit'], + 'action=massedit' => ['home', 'massedit'], + 'art action=login' => ['art', 'login'], + 'home action=login' => ['home', 'login'], + 'action=login' => ['home', 'login'], + 'aff=media' => ['media', 'desktop'], + 'aff=media action=addmedia' => ['media', 'addmedia'], + ]; + + public function __construct() { + if($this->matchroute()) { + $this->callmethod(); + } else { + echo '<h1>404 Error</h1>'; + } + } + + public function matchroute() + { + $this->route = new route($_GET); + $match = array_key_exists($this->route->tostring(), self::ROUTES); + return $match; + + } + + public function callmethod() + { + $method = self::ROUTES[$this->route->tostring()]; + + $class = 'controller' . $method[0]; + $function = $method[1]; + $controller = new $class($this->route->artid()); + $params = array_slice($method, 2); + $controller->$function(...$params); + } + + + +} + + + + + + +?>
\ No newline at end of file |