Skip to content

Commit

Permalink
upload
Browse files Browse the repository at this point in the history
  • Loading branch information
orziz committed Apr 17, 2021
1 parent 08e5075 commit c40aa24
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
27 changes: 0 additions & 27 deletions composer.json.example

This file was deleted.

48 changes: 48 additions & 0 deletions framework/Loader.php
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 added plugins/.gitkeep
Empty file.
4 changes: 3 additions & 1 deletion public/init.php
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');

0 comments on commit c40aa24

Please sign in to comment.