Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as PHP by Huso ( 16 years ago )
<?php
final class Ezrael_Loader
{
public static $_controller = null;
private static $_path = 'application/controller/';
public static $_action = null;
private static $_argument = null;
private static $_rest = false;
private static $_file = null;
private static function init()
{
if(substr($_SERVER["REQUEST_URI"], -1) != "/")
header("Location: ".$_SERVER["REQUEST_URI"]."/");
}
public static function get_controller()
{
self::check_controller();
if(!file_exists(self::$_file))
{
self::$_controller = 'error';
self::$_file = self::$_path.self::$_controller.'Controller.php';
}
require_once self::$_file;
$class = self::$_controller.'Controller';
$mycontroller = new $class();
$mycontroller->init();
if(!is_callable(array($mycontroller, self::$_action)))
$myaction = 'indexAction';
else
$myaction = self::$_action;
if(!self::$_rest)
{
if(!isset(self::$_action))
{
$mycontroller->$myaction();
}
else
{
$mycontroller->$myaction(self::$_argument);
}
}
else
{
$mycontroller->$myaction(self::$_argument, self::$_rest);
}
}
private static function check_controller()
{
self::init();
$uris = array();
$uris = self::dispatch_url();
if($uris[0] == '' || empty($uris[0]))
{
self::$_controller = 'index';
}
else
{
self::$_controller = $uris[2];
if(isset($uris[4]) and !empty($uris[4]))
{
self::$_action = $uris[4].'Action';
}
else
{
self::$_action = 'indexAction';
}
if(isset($uris[3]) and !empty($uris[3]))
self::$_argument = $uris[3];
}
self::$_file = self::$_path.self::$_controller.'Controller.php';
if(isset($uris[5]) and !empty($uris[5]))
{
self::$_rest = array();
for($i = 5; $i <= count($uris); $i++)
{
self::$_rest[$uris[$i+1]] = $uris[$i];
}
}
}
private static function dispatch_url()
{
$url = explode('/', htmlspecialchars(mysql_escape_string($_SERVER['REQUEST_URI'])));
$counter = count($url);
//Ezrael::register('first', $url[1]);
for($i = 3; $i <= count($url); $i += 2)
{
$vals[$i-1] = $url[$i-1];
$vals[$i] = $url[$i];
}
unset($vals[$counter - 1]);
return $vals;
}
}
Revise this Paste