public function __construct() { self::$instance = $this; foreach (loaded() as $name => $class) { $this->{$name} = load($class); } $this->view = load('View'); $this->load = load('Loader', 'system/core', NULL, 1); $this->view->load = $this->load; if (USE_AUTOLOAD) { $this->autoload = load('Autoload', 'system/core', NULL, 0); } if (USE_LANG) { $this->lang = load('Language'); $this->view->lang = $this->lang; } }
function load($name, $path = 'system/core', $param = NULL, $reload = 0) { static $_classes = array(); if (isset($_classes[$name]) && !$reload) { return $_classes[$name]; } $file = BASE_PATH . str_replace('/', DS, $path) . DS . $name . '.php'; if (file_exists($file)) { require_once $file; if (class_exists($name)) { if ($reload) { return isset($param) ? new $name($param) : new $name(); } $_classes[$name] = isset($param) ? new $name($param) : new $name(); loaded($name, $reload); return $_classes[$name]; } } return false; }
function autoload_classes($filename) { // where to look for including /** * for the ans we just need to look in libraries, core, config and application folder * resulting : CONTS(controller),MODS(model),CORE(core),LIB (libraries) * for rest of the class to include, use loader function */ $fileFound = FALSE; $folderSearched = FALSE; foreach (array(CONTS, MODS, CORE, LIB) as $path) { $folderSearched .= $path . "<br />"; if (file_exists($path . DS . ucwords($filename) . ".php")) { // make sure class is not defined before. if (\class_exists(\ucwords($filename)) === \FALSE) { require $path . DS . ucwords($filename) . ".php"; } $fileFound = $filename; loaded($filename); break; } } if ($fileFound === \FALSE) { echo "Unable to find file: <b>{$filename}</b>. Below is the list of folder we went through"; echo "<hr />"; echo $folderSearched; die(""); log_message("info", "unable to find filename '{$filename}'"); } // other wise return the class. }