XoopsCore
XoopsCore copied to clipboard
Roadmap: Namespace Conventions for Modules
A standard for namespace use in modules needs to be defined. Some elements to consider:
- namespace key in xoops_version.php
- autoloader conventions, for example psr-4 autoloading for the declared namespace from the class directory. A standard here would eliminate a great deal of preload chatter at startup.
An example of a xoops module namespace could be: xoops\modules\dummy
Example of usage in file ROOT/modules/dummy/class/ObjectHandler.php:
namespace xoops\modules\dummy\class; class ObjectHandler {}
Do we need a namespace key in xoops_version.php?
The XoopsLoad class would handle the mapping:
$prefix = 'xoops\\modules\\';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) === 0) {
$relative_class = substr($class, $len);
$base_dir = XOOPS_ROOT_PATH . DIRECTORY_SEPARATOR . 'modules';
$file = $base_dir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php';
if (!self::loadFile($file)) {
return false;
}
} else {
return false;
}
I started to convert some of the XOOPS 2.5.x modules to Namespaces, using "Xoopsmodules\modulename" as the top namespace, so we have in Oledrion (https://github.com/mambax7/oledrion)
namespace Xoopsmodules\Oledrion;
This can be then easily changed to whatever the Core team decides to use in the future...