<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2015 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: load.php 09594 2018-09-04 09:29:53 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:加载文件
* +----------------------------------------------------------------------
*/
namespace ticky;
class load {
private static function _load_class($classname, $path = '', $initialize = 1) {
static $classes = array();
if (empty($path))
$path = ROOT_PATH . 'tickyphp' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR;
$key = md5($path . $classname);
if (isset($classes[$key])) {
return !empty($classes[$key]) ? $classes[$key] : true;
}
if (!is_file($path . DIRECTORY_SEPARATOR . $classname . EXT)) {
return false;
}
include $path . DIRECTORY_SEPARATOR . $classname . EXT;
if ($initialize) {
$classes[$key] = new $classname;
} else {
$classes[$key] = true;
}
return $classes[$key];
}
public static function load_sys_class($classname, $path = '', $initialize = 1) {
return self::_load_class($classname, $path, $initialize);
}
public static function load_sys_func($func) {
if (is_file(ROOT_PATH . 'tickyphp' . DIRECTORY_SEPARATOR . 'function' . DIRECTORY_SEPARATOR . 'function_' . $func . '.php')) {
include ROOT_PATH . 'tickyphp' . DIRECTORY_SEPARATOR . 'function' . DIRECTORY_SEPARATOR . 'function_' . $func . '.php';
}
}
public static function load_controller($c, $m = '', $initialize = 1) {
$m = empty($m) ? MODULE_NAME : $m;
if (empty($m))
return false;
return self::_load_class($c, APP_PATH . $m . DIRECTORY_SEPARATOR . 'controller', $initialize);
}
public static function load_model($classname, $m = '', $initialize = 1) {
$m = empty($m) ? MODULE_NAME : $m;
if (empty($m))
return false;
return self::_load_class($classname, APP_PATH . $m . DIRECTORY_SEPARATOR . 'models', $initialize);
}
}