Created
May 25, 2011 16:07
-
-
Save dotmh/991254 to your computer and use it in GitHub Desktop.
A Name Space Aware PHP Auto Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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