<?php
class AutoLoader {
public function __construct() {
spl_autoload_register( array($this, 'load') );
// spl_autoload_register(array($this, 'loadComplete'));
}
// This method will be automatically executed by PHP whenever it encounters an unknown class name in the source code
private function load($className) {
if(in_array($className.'.class.php', scandir("model"))){
require_once "model/$className.class.php";
if (is_readable("sql/$className.sql.php"))
require_once "sql/$className.sql.php";
}
if (in_array($className.'.class.php', scandir("classes")))
require_once "classes/$className.class.php";
if (in_array($className.'.class.php', scandir("controller")))
require_once "controller/$className.class.php";
// TODO : compute path of the file to load (cf. PHP function is_readable)
// it is in one of these subdirectory '/classes/', '/model/', '/controller/'
// if it is a model, load its sql queries file too in sql/ directory
}
}
$__LOADER = new AutoLoader();
-
Zohten authored4ea0b48e