Skip to content

Instantly share code, notes, and snippets.

@dotmh
Created May 25, 2011 16:07
Show Gist options
  • Save dotmh/991254 to your computer and use it in GitHub Desktop.
Save dotmh/991254 to your computer and use it in GitHub Desktop.
A Name Space Aware PHP Auto Loader
class Loader
{
public function __construct()
{
spl_autoload_register(array($this , 'load'));
}
private function __clone() {}
public function load( $class )
{
if (\strpos($class, '\\') === FALSE )
{
$class = __NAMESPACE__.'\\'.$class;
}
$path = str_replace('\\', '/', $class);
$path = BASE_PATH.'/../'.$path.'.php'; // add the ext and context
if ( !\file_exists($path) )
{
return FALSE;
}
require_once($path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment