Location: PHPKode > projects > PHP Quick > PHPQuick_1.0-a/lib/core.php
<?php
/**
 * PHP Quick
 *
 * An extensible barebones web application development framework for PHP
 *
 * @package     PHP Quick
 * @author      Ihtesham Ali
 * @copyright   Copyright (c) 2011 PHP Quick
 * @license     GNU General Public License version 3.0 (GPLv3)
 * @link        http://sourceforge.net/projects/phpquick
 */

// ------------------------------------------------------------------------

/**
 * Core Functions
 *
 * Provides the core functions.
 *
 * @package		PHP Quick
 * @author		Ihtesham Ali
 */

// ------------------------------------------------------------------------

/**
 * Centralises the handling of all client requests
 *
 * @access	public
 * @param   array
 */

function front_controller($cfg)
{
	$request = parse_request();
	if(($request[0] == '') || ($request[0] == 'index.php') || ($request[0] == 'index.php?')) {
		require($cfg['default_model']);
		$page_obj = new default_class();
		$page_obj->cfg = $cfg;
		$page_obj->request = $request;
		$page_obj->default_method();
	} else {
		if(file_exists($cfg['dir_models'] . $request[0] . '.' . $cfg['mv_file_ext'])) {
			require($cfg['dir_models'] . $request[0] . '.' . $cfg['mv_file_ext']);
			if(class_exists($request[0])) {
				$page_obj = new $request[0]();
				$page_obj->cfg = $cfg;
				$page_obj->request = $request;
				if(method_exists($page_obj, $request[1])) {
					$page_obj->$request[1]();
				} elseif(empty($request[1])) {
					$page_obj->default_method();
				} else {
					require($cfg['dir_errors'] . 'error_404.php');
					$page_obj = new error_404();
					$page_obj->display_error();
				}
			} else {
				require($cfg['dir_errors'] . 'error_404.php');
				$page_obj = new error_404();
				$page_obj->display_error();
			}
		} else {
			require($cfg['dir_errors'] . 'error_404.php');
			$page_obj = new error_404();
			$page_obj->display_error();
		}
	}
}

// ------------------------------------------------------------------------

/**
 * Parses the client request made through URL
 *
 * @access  public
 * @return  array
*/

function parse_request()
{
	if(isset($_GET['c'])) {
		foreach($_GET as $val) {
			$request[] = addslashes(trim($val));
		}
	return $request;
	} else {
		$req = explode('/', substr($_SERVER['REQUEST_URI'], 1));
		foreach($req as $val) {
			$request[] = addslashes(trim($val));
		}
	return $request;
	}
}

?>
Return current item: PHP Quick