Autoloading out of the /classes folder is fully PRS-0 compliant in Elgg 1.9 but is quite crude in Elgg 1.8. If you need PSR-0 compatibility in 1.8, you can use this snippet in your plugin's start.php:
// fix autoloading for 1.8 (place this in plugin start.php)
if (version_compare(get_version(true), '1.9', '<')) {
spl_autoload_register(function ($class) {
$pieces = explode('\\', ltrim($class, '\\'));
$pieces[count($pieces) - 1] = strtr($pieces[count($pieces) - 1], '_', '/');
$file = __DIR__ . '/classes/' . implode('/', $pieces) . '.php';
is_readable($file) && (require $file);
});
}
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
BTW, this requires PHP 5.3.
Many thanks! Actually for me
I'm using autoloaded classes in 1.8 - it appears to be working fine without this but I'm unfamiliar with PSR-0 - is there any need for this for functional reasons?
If so this can be added 1.8.17 I would assume - with a php version check?
Elgg 1.8 maps files very naively: /classes/ + class_name + .php
So you can't use namespaced classes at all.
Thanks, This Is Good For Me...