Add autoloader

This commit is contained in:
Ivan Shalganov
2014-04-17 23:50:18 +04:00
parent e740bb2bd9
commit 02368a0a47
3 changed files with 26 additions and 2 deletions

View File

@@ -964,4 +964,22 @@ class Fenom
}
return $mask;
}
/**
* Register PSR-0 autoload for Fenom
* @param string $dir custom directory for autoloading, if NULL — autoload itself
* @return bool
*/
public static function registerAutoload($dir = null)
{
if(!$dir) {
$dir = __DIR__;
}
return spl_autoload_register(function($classname) use ($dir) {
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $classname).'.php';
if(is_file($file)) {
require_once $file;
}
});
}
}