Location: PHPKode > projects > SkullPuppy > Project/library/SP/Router.php
<?php

class SP_Router {
	private static $instance;
	private $_routes, $_currentRoute;

	public function __construct() {
		$this->_routes = array();
		array_push($this->_routes, new SP_Route(':module/:controller/:action',
				array()));
		$this->_routes['default'] = new SP_Route(':controller/:action/*',
				array());
	}

	public static function getInstance() {
		if (!isset(self::$instance)) self::$instance = new SP_Router;
		return self::$instance;
	}

	public function addRoute($name, $route) {
		if(!($route instanceof SP_Route)) return false;
		$this->_routes = array_merge( array((string) $name => $route),
			$this->_routes);
		return true;
	}

	public function getRoute($name = null) {
		if($name === null) $name = $this->_currentRoute;
		return $this->_routes[$name];
	}

	public function setCurrentRoute($name = null) {
		if(!$name) return false;
		return $this->_currentRoute = (string) $name;
	}

	public function matchRoute() {
		$uri = explode('/',$_SERVER['REQUEST_URI']);
		if(!$uri[0]) array_shift ($uri);
		if(!end($uri)) array_pop ($uri);
		if(!$uri) {
			if(SP_Registry::getKey('force_default_module'))
				array_push($uri,'default');
			array_push($uri,'index');
			array_push($uri,'index');
		}
		$count = count($uri);
		foreach($this->_routes as $key => $route) {
			if($route->count() == $count || (($route->count() < $count) &&
					$route->hasWild())) {
				if($route->match($uri)) {
					return $route->dispatch();
				}
			}
		}
		throw new SP_Exception('Unable to find a matching route!');
	}

	public function __clone() {
		throw SP_Exception('Cloning of SP_Router is not allowed.');
	}
}

?>
Return current item: SkullPuppy