Skip to content

Instantly share code, notes, and snippets.

@jfensign
Created April 6, 2012 20:58
Show Gist options
  • Save jfensign/2322875 to your computer and use it in GitHub Desktop.
Save jfensign/2322875 to your computer and use it in GitHub Desktop.
Front Controller
<?php
//App class
class App {
//Holds Singleton instance
public static $instance;
//environment vars
public static $vars = array();
private function __construct() {}
//Create Singleton
public static function get_instance() {
if(empty(self::$instance)) {
self::$instance = new App();
}
return self::$instance;
}
public function __toString() {
return implode(", ", self::$vars);
}
//SET URI ARGUMENT
public static function set_vars(array $v) {
self::$vars = $v;
}
//RETRIEVE URI ARGUMENT
public static function get_vars() {
return self::$vars;
}
//CALLS LOADER CLASS
public static function load() {
require_once('Load.php');
return new Load();
}
}//End Class App
?>
<?php
//index.php
if(!ob_start("ob_gzhandler")) ob_start();
@!$_SESSION || @empty($_SESSION) ? session_start() : NULL;
//Require App
require_once('App.php');
/*
*ARRAY $uri
*converts the current uri into an array
*truncating the domain name. The uri elements are then used to identify/call
*system components
*/
$protocol = $_SERVER['HTTPS'] ? "https://" : "http://";
$app_path = $protocol . $_SERVER['HTTP_HOST'] . "/" . basename(__FILE__);
$uri = $_SERVER['REQUEST_URI'];
$uri = str_replace($app_path, "", $uri);
$uri = str_replace("?" . $_SERVER["QUERY_STRING"], "", $uri);
$uri = preg_split('[\\/]', $uri, -1, PREG_SPLIT_NO_EMPTY);
//define constant VALID_APP to prevent direct script access.
define("VALID_APP", TRUE);
//sends URI array to App for initialization/instantiation
App::set_vars($uri_array);
ob_end_flush();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment