* modifications related to enabling memcache and adding some expire headers
[vsc.git] / _res / _libs / tsrouter.class.php
blob4f52c9be686f521213dcbce668fd8deb9845654a
1 <?php
3 class tsRouter {
4 protected $routes = array(),
5 $defaultRoute;
7 public function __construct () {
10 public function addRoute ($ctrlName, $incRoute = null, $default = null) {
11 if (empty ($ctrlName)) {
12 return false;
15 if (empty ($incRoute))
16 $incRoute = '/'.$ctrlName.'/';
18 if ($default)
19 $this->defaultRoute = $ctrlName;
21 $this->routes[$ctrlName] = $incRoute;
23 return true;
26 public function getController () {
27 $to = urldecode(tsUrl::getRequest(NAV_VAR));
28 // var_dump($_GET, $to);
30 if ($this->validController ($to)) {
31 return tsController::getInstance ($to);
33 // die;
34 foreach ($this->routes as $ctrlName => $regex) {
35 // var_dump($to, $ctrlName, $regex,preg_match('/'.$ctrlName.'/i', $to), preg_match($regex, $to,$a));
36 if ((preg_match('/'.$ctrlName.'/i', $to) || preg_match($regex, $to)) && $this->validController ($ctrlName)) {
37 return tsController::getInstance ( $ctrlName);
40 // die;
41 if ($this->validController ($this->defaultRoute))
42 return new $this->defaultRoute;
43 // try index if it exists
44 if ($this->validController ('index'))
45 return tsController::getInstance ('index');
46 // die;
49 public function validController ($ctrlName) {
50 $ctrlName = strtolower($ctrlName);
51 // var_dump($ctrlName);
53 if (!empty($ctrlName) && is_dir(PAGE_PATH . $ctrlName) && is_file (PAGE_PATH . $ctrlName . DIRECTORY_SEPARATOR . $ctrlName . '.class.php')) {
54 return true;
57 return false;