You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
844 B
25 lines
844 B
2 months ago
|
<?php
|
||
|
namespace LaneWeChat;
|
||
|
|
||
|
class Autoloader{
|
||
|
const NAMESPACE_PREFIX = 'LaneWeChat\\';
|
||
|
|
||
|
public static function register(){
|
||
|
spl_autoload_register(array(new self, 'autoload'));
|
||
|
}
|
||
|
|
||
|
|
||
|
public static function autoload($className){
|
||
|
$namespacePrefixStrlen = strlen(self::NAMESPACE_PREFIX);
|
||
|
if(strncmp(self::NAMESPACE_PREFIX, $className, $namespacePrefixStrlen) === 0){
|
||
|
$className = strtolower($className);
|
||
|
$filePath = str_replace('\\', DIRECTORY_SEPARATOR, substr($className, $namespacePrefixStrlen));
|
||
|
$filePath = realpath(__DIR__ . (empty($filePath) ? '' : DIRECTORY_SEPARATOR) . $filePath . '.lib.php');
|
||
|
if(file_exists($filePath)){
|
||
|
require_once $filePath;
|
||
|
}else{
|
||
|
echo $filePath;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|