Hi everybody,
I use modx on everyday basis. I like it and am really excited waiting for Revolution release. I am real fan of all that OOP stuff.
However, I was a little disappointed seeing how library is organized. First, why class names start with lower case letters and why do we need suffix ’class’? I think it is understandable enough that in class folders we will find classes (so ’modaccesscontext.class.php’ -> ’ModAccessContext.php’).
Next, I think it is already conventional for PHP to use library structure where class name represents where file is located in the library (like in Zend).
So,
proposal is to, for example, change ’modaccesscontext.class.php’ to: MODx/Access/Context.php with class name MODx_Access_Context.
Simple autoloader example for this type of library structure:
class Autoloader
{
public static $dirs = array();
public static function addDirectory($dir){
self::$dirs[] = $dir . '/';
}
public static function register(){
spl_autoload_register(array(self, 'load'));
}
public static function load($name){
$fname = str_replace('_', '/', $name) . '.php';
foreach(self::$dirs as $dir)
if(file_exists($full_fname = $dir . $fname)) return require_once($full_fname);
}
}
// Usage:
Autoloader::addDirectory('...core/model');
Autoloader::register();
$var = new MODx_Access_Context();
// Include custom dirs at runtime
Autoloader::addDirectory('...my/extra/dir');