Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Created May 23, 2013 20:30
Show Gist options
  • Save alixaxel/5639177 to your computer and use it in GitHub Desktop.
Save alixaxel/5639177 to your computer and use it in GitHub Desktop.
Lightweight, PSR-0 compliant SPL Autoloader
<?php
$paths = array
(
__DIR__ . '/vendor/',
__DIR__ . '/vendor/phunction/phunction.php',
);
foreach ($paths as $path)
{
if (is_dir($path) === true)
{
spl_autoload_register(function ($class) use ($path)
{
if (($namespace = strrpos($class = ltrim($class, '\\'), '\\')) !== false)
{
$path .= strtr(substr($class, 0, ++$namespace), '\\', '/');
}
require($path . strtr(substr($class, $namespace), '_', '/') . '.php');
});
}
else if (is_file($path) === true)
{
require($path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment