Skip to content

Instantly share code, notes, and snippets.

@mrclay
Created August 26, 2013 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrclay/6340956 to your computer and use it in GitHub Desktop.
Save mrclay/6340956 to your computer and use it in GitHub Desktop.
PSR-0 class autoloader shim for Elgg 1.8
<?php
/**
* Enables full PSR-0 class autoloading out of /classes directory
*
* Usage in start.php:
*
* if (!function_exists('elgg_get_version')) {
* require_once __DIR__ . '/19-autoloader.php';
* }
*/
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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment