Skip to content

Instantly share code, notes, and snippets.

@Dynom
Created October 16, 2012 14:23
Show Gist options
  • Save Dynom/3899573 to your computer and use it in GitHub Desktop.
Save Dynom/3899573 to your computer and use it in GitHub Desktop.
psr-autoloader.php
<?php
spl_autoload_register(
function ($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
return $fileName . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment