Skip to content

Instantly share code, notes, and snippets.

@Sketches-su
Created April 13, 2015 10:23
Show Gist options
  • Save Sketches-su/b5090e2284324bfc211e to your computer and use it in GitHub Desktop.
Save Sketches-su/b5090e2284324bfc211e to your computer and use it in GitHub Desktop.
Quick&dirty PSR-0 implementation (tested)
spl_autoload_register(function ($class)
{
$file = __DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR;
if ($class[0] == '\\') {
$class = ltrim($class, '\\');
}
if (false !== ($pos = strrpos($class, '\\'))) {
$file .= str_replace(
'\\',
DIRECTORY_SEPARATOR,
substr($class, 0, ++$pos)
);
}
$file .= str_replace(
'_',
DIRECTORY_SEPARATOR,
$pos ? substr($class, $pos) : $class
).'.php';
if (file_exists($file)) {
require $file;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment