36 lines
842 B
PHP
36 lines
842 B
PHP
<?php
|
|
|
|
$vnAutoloadReplace = function($matches) {
|
|
$match = strtolower($matches[0]);
|
|
|
|
if (strlen($match) == 1)
|
|
return $match;
|
|
if ($match{0} == '\\')
|
|
return DIRECTORY_SEPARATOR. $match{1};
|
|
|
|
return $match{0} .'-'. $match{1};
|
|
};
|
|
|
|
spl_autoload_register(function($className) {
|
|
global $vnAutoloadReplace, $vnAutoloadMap;
|
|
|
|
$classPath = preg_replace_callback('/.?[A-Z]/', $vnAutoloadReplace, $className);
|
|
$classPath .= '.php';
|
|
|
|
if (isset($vnAutoloadMap))
|
|
foreach($vnAutoloadMap as $prefix => $location) {
|
|
$prefixLen = strlen($prefix);
|
|
|
|
if (strncmp($classPath, $prefix, $prefixLen) == 0) {
|
|
$classPath = "$location/". substr($classPath, $prefixLen);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($classPath{0} != DIRECTORY_SEPARATOR)
|
|
$classPath = stream_resolve_include_path($classPath);
|
|
|
|
if (file_exists($classPath))
|
|
require_once $classPath;
|
|
});
|