首页 > CMS技巧 > PHPCMS > 内容

分析phpcms v9执行过程之二

继续分析phpcms v9执行过程:phpcms v9执行过程之二

PHPCMS执行过程在这application.class.php 文件中,下面我以注释的形式解释PHPCMS执行过程
<?php
/*
* application.class.php PHPCMS应用程序创建类
*/
class application {
/**
* 构造函数,实例化此类的时候,自动执行
*/
public function __construct() {
$param = pc_base::load_sys_class('param'); //实例化param.class.php参数处理类
public function __construct() {
if(!get_magic_quotes_gpc()) {
$_POST = new_addslashes($_POST); //new_addslashes()为全局函数
$_GET = new_addslashes($_GET);
$_REQUEST = new_addslashes($_REQUEST);
$_COOKIE = new_addslashes($_COOKIE);
}
$this->route_config = pc_base::load_config('route', SITE_URL) ? pc_base::load_config('route', SITE_URL) : pc_base::load_config('route', 'default');


if(isset($this->route_config['data']['POST']) && is_array($this->route_config['data']['POST'])) {
foreach($this->route_config['data']['POST'] as $_key => $_value) {
if(!isset($_POST[$_key])) $_POST[$_key] = $_value;
}
}
if(isset($this->route_config['data']['GET']) && is_array($this->route_config['data']['GET'])) {
foreach($this->route_config['data']['GET'] as $_key => $_value) {
if(!isset($_GET[$_key])) $_GET[$_key] = $_value;
}
}
if(isset($_GET['page'])) $_GET['page'] = max(intval($_GET['page']),1);
return true;
}
define('ROUTE_M', $param->route_m());
/**
* 获取模型
*/
public function route_m() {
$m = isset($_GET['m']) && !empty($_GET['m']) ? $_GET['m'] : (isset($_POST['m']) && !empty($_POST['m']) ? $_POST['m'] : '');
if (empty($m)) {
return $this->route_config['m'];
} else {
return $m;
}
}
define('ROUTE_C', $param->route_c());
define('ROUTE_A', $param->route_a());
$this->init();
}

/**
* 调用件事
*/
private function init() {
$controller = $this->load_controller();
if (method_exists($controller, ROUTE_A)) {
if (preg_match('/^[_]/i', ROUTE_A)) {
exit('You are visiting the action is to protect the private action');
} else {
call_user_func(array($controller, ROUTE_A));
}
} else {
exit('Action does not exist.');
}
}

/**
* 加载控制器
* @param string $filename
* @param string $m
* @return obj
*/
private function load_controller($filename = '', $m = '') {
if (empty($filename)) $filename = ROUTE_C;
if (empty($m)) $m = ROUTE_M;
$filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.php';
if (file_exists($filepath)) {
$classname = $filename;
include $filepath;
if ($mypath = pc_base::my_path($filepath)) {
$classname = 'MY_'.$filename;
include $mypath;
}
return new $classname;
} else {
exit('Controller does not exist.');
}
}
}

上一篇:分析phpcms v9执行过程之三
下一篇:分析PHPCMS V9执行过程之一

分享到:
      加入收藏
信息速递
信息速递