Code refactoring, #16

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@115 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
pzinovkin
2010-02-26 22:33:07 +00:00
parent 1b422d87ba
commit e33f2a8536
5 changed files with 121 additions and 34 deletions

View File

@ -12,26 +12,53 @@
class Load
{
static protected $file;
static protected $autoload;
static public function setAutoloadFrom($file)
{
self::$file = $file;
if (!file_exists(self::$file)) {
self::buildAutoload();
}
self::$autoload = require(self::$file);
}
static public function autoload($class)
{
if (! isset(self::$autoload[$class])) {
throw new MJException('There is no such class "' . $class . '" in autoload.');
if (isset(self::$autoload[$class])) {
require(PATH . self::$autoload[$class]);
return;
}
require(PATH . self::$autoload[$class]);
}
static public function setAutoloadFrom($file)
{
if (! file_exists($file)) {
throw new MJException('Autoload source doesn\'t exists! Try to generate it!');
if (defined('DEBUG') && DEBUG == true) {
if (!isset(self::$autoload[$class])) {
self::buildAutoload();
}
if (isset(self::$autoload[$class])) {
require(PATH . self::$autoload[$class]);
}
}
self::$autoload = require($file);
}
static public function getFilePath($class)
{
return self::$autoload[$class];
}
static protected function buildAutoload()
{
ignore_user_abort(true);
$dir = dirname(self::$file);
if (!file_exists($dir) && !mkdir($dir)) {
trigger_error('Can\'t create directory: "' . $dir . '"', E_USER_ERROR);
}
$scan = array(PATH . '/lib', PATH . '/' . APP . '/src');
require_once(PATH . '/lib/core/util/AutoloadBuilder.php');
$builder = new AutoloadBuilder(self::$file, $scan);
$builder->build();
ignore_user_abort(false);
}
}