<?php
 namespace TCMS;
 class Route {
 private $routes = [];
 public function _get($url, $controller, $action = 'index') {
 $route = new TCmsRouteUrl($url, $controller, $action, \ENUM_METHOD::GET);
 $this->routes[] = $route;
 return $route;
 }
 public function _post($url, $controller, $action = 'postIndex') {
 $route = new TCmsRouteUrl($url, $controller, $action, \ENUM_METHOD::POST);
 $this->routes[] = $route;
 return $route;
 }
 public function getAllRoutes() {
 return $this->routes;
 }
 public function findRouteByName($routeName) {
 foreach($this->routes as $r) {
 if($r->name != null && $r->name == $routeName) {
 return url($r->url);
 }
 }
 return '';
 }
 public function __destruct() {
 $this->routes = null;
 }
 }
 class TCmsRouteUrl {
 public $url = null;
 public $controller = null;
 public $action = null;
 public $type = 0;
 public $regex = null;
 public $name = '';
 public function __construct($url, $controller, $action, $type) {
 $this->url = $url;
 $this->controller = $controller;
 $this->action = $action;
 $this->type = $type;
 }
 public function where($key, $regex) {
 if($this->regex == null) $this->regex = [];
 $this->regex[$key] = $regex;
 return $this;
 }
 public function name($name) {
 $this->name = $name;
 return $this;
 }
 }
 ?>