解读微擎 之load()函数 ----loader.class.php


loader.class.php  虽然下面module()方法还不太明白,但是大概知道 其他文件加载这个文件之后会   

用load()->("文件名前缀"),加载framework下文件

<?php
/**
 * [WeEngine System] Copyright (c) 2014 WE7.CC
 * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
 */
defined('IN_IA') or exit('Access Denied');

//检测是否定义了IN_IA这个变量否则停止输出Access Denied
//本文件是在bootstrap.inc.php中加载的,bootstrap.inc.php中定义了这个变量,变相的验证在加载本文件之前是否加载了bootstrap.inc.php


function load() {
	static $loader;//静态变量能直接访问
	if(empty($loader)) {
		$loader = new Loader();
	}
	return $loader;
}


class Loader {
	
	//public 表示全局,类内部外部子类都可以访问;
    //private表示私有的,只有本类内部可以使用;
	//protected表示受保护的,只有本类或子类或父类中可以访问;
	private $cache = array();
	
	function func($name) {
		global $_W;
		
		if (isset($this->cache['func'][$name])) {
			return true;//检测这个数组值是否存在
		}
		$file = IA_ROOT . '/framework/function/' . $name . '.func.php';
		//file_exists检查文件是否存在 返回布尔值
		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);
			//疑问  E_USER_ERROR 是在哪定义的变量
			return false;
		}
	}
	//下面几个函数和上面func类似是用load()->("文件名前缀")的方式加载framework下文件的方式
	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;
		}
	}
	
	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;
		}
	}
	
	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;
		}
	}
	
	function module($module, $file) {
		if (isset($this->cache['encrypte'][$name])) {
			return true;
		}
		//file_get_contents() 把整个文件内的所有读入一个字符串中。
		//这里的$name哪来的
		if (strexists(file_get_contents($name), '<?php')) {
			$this->cache['encrypte'][$name] = true;
			require $name;
		} else {
			//cache_load????
			$key = cache_load('module:cloud:key:1');
			$vars = cache_load('module:cloud:vars:1');
			if (empty($vars)) {
				trigger_error('Module is missing critical files , please reinstall');
			}
			//<<<Eof
			//……
			//Eof;
			//1.PHP定界符的作用就是按照原样,包括换行格式什么的,输出在其内部的东西;
			//2.在PHP定界符中的任何特殊字符都不需要转义;
			//3.PHP定界符中的PHP变量会被正常的用其值来替换。
			echo <<<EOF
\$_ENV = unserialize(base64_decode('$vars'));
EOF;
			
			
			exit;
		}
	}
}


猜你喜欢

转载自blog.csdn.net/qq_39940866/article/details/78041639
今日推荐