1 Star 12 Fork 5

a07061625 / pay

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
autoload.php 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
紫血剑神 提交于 2020-02-14 22:53 . fixed error for autoload
<?php
/**
* Created by PhpStorm.
* User: 姜伟
* Date: 2019/11/30 0030
* Time: 19:26
*/
define('SY_ENV', 'dev'); //环境类型,支持dev:开发环境 product:正式环境
define('SY_PROJECT', 'a01'); //项目标识,3位长度,数字和小写字母组成
define('SY_ROOT', __DIR__);
define('SY_FRAME_LIBS_ROOT', SY_ROOT . '/'); // 加载器起始加载的根目录,以/结尾
final class SyFrameLoader
{
/**
* @var \SyFrameLoader
*/
private static $instance = null;
/**
* @var array
*/
private $preHandleMap = [];
private function __construct()
{
$this->preHandleMap = [
];
}
private function __clone()
{
}
/**
* @return \SyFrameLoader
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* 加载文件
* @param string $className 类名
* @return bool
*/
public function loadFile(string $className) : bool
{
$nameArr = explode('/', $className);
$funcName = $this->preHandleMap[$nameArr[0]] ?? null;
if (is_null($funcName)) {
$nameArr = explode('_', $className);
$funcName = $this->preHandleMap[$nameArr[0]] ?? null;
}
$file = is_null($funcName) ? SY_FRAME_LIBS_ROOT . $className . '.php' : $this->$funcName($className);
if (is_file($file) && is_readable($file)) {
require_once $file;
return true;
}
return false;
}
}
/**
* 基础公共类自动加载
* @param string $className 类全名
* @return bool
*/
function syFrameAutoload(string $className)
{
$trueName = str_replace([
'\\',
"\0",
], [
'/',
'',
], $className);
return SyFrameLoader::getInstance()->loadFile($trueName);
}
spl_autoload_register('syFrameAutoload');
PHP
1
https://gitee.com/a07061625/pay.git
git@gitee.com:a07061625/pay.git
a07061625
pay
pay
master

搜索帮助