Files
youlegames/codes/agent/game/api/framework/class/loader.class.php
2026-03-15 01:27:05 +08:00

99 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
defined('IN_IA') or exit('Access Denied');
function load() {
static $loader;
if(empty($loader)) {
$loader = new Loader();
}
return $loader;
}
class Loader {
// 缓存数组
private $cache = array();
// 加载指定的函数文件,并在$cache中做好已经加载成功的标识
function func($name) {
global $_W;
if (isset($this->cache['func'][$name])) {
return true;
}
$file = IA_ROOT . '/framework/function/' . $name . '.func.php';
if (file_exists($file)) {
include $file;
$this->cache['func'][$name] = true;
return true;
} else {
trigger_error('Invalid Helper Function /framework/function/' . $name . '.func.php', E_USER_ERROR);
return false;
}
}
// 加载指定的model并在$cache用cache['model']的方式标识好是否加载成功
function model($name) {
global $_W;
if (isset($this->cache['model'][$name])) {
return true;
}
$file = IA_ROOT . '/framework/model/' . $name . '.mod.php';
if (file_exists($file)) {
include $file;
$this->cache['model'][$name] = true;
return true;
} else {
trigger_error('Invalid Model /framework/model/' . $name . '.mod.php', E_USER_ERROR);
return false;
}
}
// 加载指定的类,并在$cache用cache['class']的方式标识好是否加载成功
function classs($name) {
global $_W;
if (isset($this->cache['class'][$name])) {
return true;
}
$file = IA_ROOT . '/framework/class/' . $name . '.class.php';
if (file_exists($file)) {
include $file;
$this->cache['class'][$name] = true;
return true;
} else {
trigger_error('Invalid Class /framework/class/' . $name . '.class.php', E_USER_ERROR);
return false;
}
}
function web($name) {
global $_W;
if (isset($this->cache['web'][$name])) {
return true;
}
$file = IA_ROOT . '/web/common/' . $name . '.func.php';
if (file_exists($file)) {
include $file;
$this->cache['web'][$name] = true;
return true;
} else {
trigger_error('Invalid Web Helper /web/common/' . $name . '.func.php', E_USER_ERROR);
return false;
}
}
// 加载指定的前端app函数并在$cache用cache['app']的方式标识好是否加载成功
function app($name) {
global $_W;
if (isset($this->cache['app'][$name])) {
return true;
}
$file = IA_ROOT . '/app/common/' . $name . '.func.php';
if (file_exists($file)) {
include $file;
$this->cache['app'][$name] = true;
return true;
} else {
trigger_error('Invalid App Function /app/common/' . $name . '.func.php', E_USER_ERROR);
return false;
}
}
}