-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
28 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace kjBot\Framework; | ||
|
||
class Loader | ||
{ | ||
/* 路径映射 */ | ||
public static $vendorMap = array( | ||
// 核心层 | ||
"kjBot" => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR, | ||
'kjBot\\SDK' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . "SDK", | ||
'kjBot\\Framework' => __DIR__ . DIRECTORY_SEPARATOR, | ||
'kjBotModule' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'modules', | ||
'kjBotPlugin' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'plugins' | ||
); | ||
|
||
/** | ||
* 自动加载器 | ||
*/ | ||
public static function autoload($class) | ||
{ | ||
$file = self::findFile($class); | ||
if (file_exists($file)) { | ||
self::includeFile($file); | ||
} | ||
} | ||
|
||
/** | ||
* 解析文件路径 | ||
*/ | ||
private static function findFile($class) | ||
{ | ||
$vendor = substr($class, 0, strpos($class, '\\')); // 顶级命名空间 | ||
$vendorDir = self::$vendorMap[$vendor]; // 文件基目录 | ||
$filePath = substr($class, strlen($vendor)) . '.php'; // 文件相对路径 | ||
return strtr($vendorDir . $filePath, '\\', DIRECTORY_SEPARATOR); // 文件标准路径 | ||
} | ||
|
||
/** | ||
* 引入文件 | ||
*/ | ||
private static function includeFile($file) | ||
{ | ||
if (is_file($file)) { | ||
include $file; | ||
} | ||
} | ||
} |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
<?php | ||
|
||
include_once('../vendor/autoload.php'); | ||
include_once('../plugins.php'); | ||
include_once('../modules.php'); | ||
include_once('../framework/Loader.php'); | ||
spl_autoload_register('\kjBot\Framework\Loader::autoload'); | ||
|
||
|
||
$Config = parse_ini_file('../config.ini'); |