Location: PHPKode > scripts > Smart URI > smart-uri/lib/class.driver.inc
<?
////////////////////////////////////////////////////////////////
// SmartURI v0.9.1 (c) Gregory A. Rozanoff, 2005.
// (c) Gregory A, Rozanoff, 2004, 2005
////////////////////////////////////////////////////////////////

function __CONTAINER__($_URI, $_SELF, $_PATH) {
	if (file_exists($_PATH.$_SELF.".php")) require $_PATH.$_SELF.".php";
		else return TRUE;
	return $_ERROR;
}

////////////////////////////////////////////////////////////////
// Class source
////////////////////////////////////////////////////////////////

class driver {

 // Variables

 var
 	$_VERSION	= "SmartURI v0.9.1 (c) Gregory A. Rozanoff, 2005.",
	$ACTION_DIR	= 'e:/localhost/www/q/actions/',	// Modules directory
	$_GZIP		= TRUE;					// Use gZIP compression
 
 // Public methods

 function driver ($run) {
	ob_start($this->_GZIP ? 'ob_gzhandler' : NULL);
	ob_implicit_flush(FALSE);
 
	list($path, $args) = explode("?", $_SERVER['REQUEST_URI']);
	$this->_URI = explode("/", $path);
	array_shift($this->_URI);
	$this->_FOO = $this->_parse($run);
 }
 
 function execute() {
	if (@__CONTAINER__($this->_URI, $this->_FOO, $this->ACTION_DIR))
		$this->_error(403, "Invalid wrapper <b>{$this->_FOO}</b>.");
 }

 function done() {
	ob_end_flush();
	unset($this);
 }

 // Private methods

 function _parse($run) {
	$item = array_shift($this->_URI);
	if ($item == '' && isset($run["#"])) return $run["#"];
	elseif ('array' == gettype($run[$item])) return $this->_parse($run[$item]);
	elseif ($item != '' && isset($run["*"])) {
		array_unshift($this->_URI, $item);
		return $run["*"];
	} else $this->_error(404, "<b>{$_SERVER['REQUEST_URI']}</b> not found on this site.");
 }

 function _error($err, $msg) {
	switch ($err) {
		case 404:
			header("HTTP/1.0 404 Not Found");
			header("Status: 404 Not Found");
			break;
		case 403:
			header("HTTP/1.0 403 Forbidden");
			header("Status: 403 Forbidden");
			break;
	}
	ob_end_clean();
	die ("<pre><h1>$err error:</h1><ul><li>$msg</li></ul><hr />{$this->_VERSION}</pre>");
 }
}

?>
Return current item: Smart URI