<?php
/************************************************
*
* Amysql PHP MVC
* Amysql.com
* @param Object $AmysqlProcess 网站进程
*
*/
class Amysql {
public $AmysqlProcess;
public function Amysql()
{
global $Config;
ini_set("magic_quotes_runtime", false);
($Config['DebugPhp'] && error_reporting(E_ALL)) || error_reporting(0); // 是否报错
($Config['SessionStart'] && session_start()); // SESSION
(!empty($Config['CharSet']) && header('Content-type: text/html;charset=' . $Config['CharSet']));
}
static public function AmysqlNotice($notice)
{
$AmysqlController = new AmysqlController();
$AmysqlController -> notice = $notice;
$AmysqlController -> _view('AmysqlNotice');
exit();
}
}
/************************************************
*
* 总进程对象
* @param Object $ControllerName 控制器对象
* @param string $ControllerName 控制器名称
* @param string $ActionName 方法名称
* @param string $ControllerFile 控制器文件
*
*/
class AmysqlProcess {
public $AmysqlController;
public $ControllerName;
public $ActionName;
public $ControllerFile;
function ProcessStart()
{
global $Config;
if ($Config['HttpPath'])
{
$GETParam = (strlen($_SERVER['REQUEST_URI']) > strlen($_SERVER['SCRIPT_NAME'])) ? explode('/', trim(str_ireplace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']), '/')) : '';
$GETCount = count($GETParam);
if($GETCount > 1)
for ($i=2; $i<$GETCount; ++$i) $_GET[$GETParam[$i]] = isset($GETParam[++$i]) ? $GETParam[$i] : '';
}
($Config['Filter'] && !get_magic_quotes_gpc() &&
($this -> filter($_GET) && $this -> filter($_POST) && $this -> filter($_COOKIE) && $this -> filter($_FILES))); // 是否过滤
$this -> ControllerName = !empty($GETParam[0]) ? $GETParam[0] : ( (isset($_GET[$Config['UrlControllerName']]) && !empty($_GET[$Config['UrlControllerName']])) ? $_GET[$Config['UrlControllerName']] : 'index');
$this -> ControllerName = str_replace(_PathTag, DIRECTORY_SEPARATOR, $this -> ControllerName);
$this -> ActionName = !empty($GETParam[1]) ? $GETParam[1] : ( (isset($_GET[$Config['UrlActionName']]) && !empty($_GET[$Config['UrlActionName']])) ? $_GET[$Config['UrlActionName']] : 'IndexAction');
$this -> ControllerFile = _Controller . $this -> ControllerName . '.php';
}
function ControllerStart()
{
((is_file($this -> ControllerFile) && include_once($this -> ControllerFile)) ||
(is_file(_Controller . 'index.php') && include_once(_Controller . 'index.php')) ||
Amysql::AmysqlNotice($this -> ControllerFile . ' 控制器文件不存在'));
(class_exists($this -> ControllerName) || (($this -> ControllerName = 'index') && class_exists('index')) ||
Amysql::AmysqlNotice($this -> ControllerName . ' 控制器不存在'));
$methods = get_class_methods($this -> ControllerName); // 获取类中的方法名
(in_array($this -> ActionName, $methods, true) ||
(($this -> ActionName = 'IndexAction') && in_array($this -> ActionName, $methods, true)) ||
Amysql::AmysqlNotice($this -> ActionName . ' 方法不存在'));
$this -> AmysqlController = new $this->ControllerName($_GET); // 实例控制器
$this -> AmysqlController -> {$this -> ActionName}(); // 执行方法
}
function filter(&$array)
{
if (!is_array($array)) Return false;
foreach ($array as $key => $value)
(is_array($value) && $this -> filter($value)) || $array[$key] = addslashes($value);
Return true;
}
}
/************************************************
*
* 控制器逻辑层 (C)
* @param Object $DB 数据库对象
* @param Array $DBConfig 链接配置
* @param Array $AmysqlModel 模型对象集
* @param Object $AmysqlTemplates 模板对象
* @param Array $EchoData 调试数据
*
*/
class AmysqlController {
public $DB;
public $DBConfig; // 控制器调用Mysql的链接配置
public $AmysqlModel; // 控制器关联的数据模型对象集
public $AmysqlClass; // 控制器关联的类对象集
public $AmysqlTemplates; // 控制器关联的模板对象
public $EchoData = array(); // 调试数据
function AmysqlController()
{
global $Config;
$this -> DBConfig = $Config;
$this -> DB = new DB();
$this -> AmysqlTemplates = new AmysqlTemplates();
}
/**
* 设置数据库配置
* @param Array $Config 链接配置
*/
function _DBSet($_Config = NULL)
{
global $Config;
$_Config = ($_Config == NULL) ? $Config : $_Config;
foreach ($Config as $key=>$val)
(empty($_Config[$key]) && $_Config[$key] = $val);
$this -> DBConfig = $_Config;
}
/**
* 模板赋值
* @param string $name 名称
* @param string $value 值
*/
public function __set($name, $value = NULL)
{
$this -> AmysqlTemplates -> TemplateValue[$name] = $value;
}
/**
* 数组模板赋值
* @param Array $array 数据
*/
public function _array($array)
{
if (is_array($array))
{
foreach ($array as $key=>$val)
$this -> AmysqlTemplates -> TemplateValue[$key] = $val;
}
}
/**
* 加载自定义类文件
* @param string $file 文件名
* @param string $ClassName 类名(可选,默认为文件名)
* @return Object $ClassName() 类对象
*/
public function _class($file, $ClassName = NULL)
{
$file = str_replace(_PathTag, DIRECTORY_SEPARATOR, $file);
$ClassName = ($ClassName == NULL) ? $file : $ClassName;
$file = _Class . $file . '.php';
if(is_file($file))
{
include_once($file);
if(!class_exists($ClassName))
Amysql::AmysqlNotice($ClassName . ' 类对象不存在');
if(!isset($this -> AmysqlClass[$ClassName])) // 不存在类对象
$this -> AmysqlClass[$ClassName] = new $ClassName();
Return $this -> AmysqlClass[$ClassName];
}
Amysql::AmysqlNotice($file . ' 类文件不存在');
}
/**
* 加载模型文件
* @param string $file 文件名
* @param string $ClassName 模型名(可选,默认为文件名)
* @return Object $ClassName() 模型对象
*/
public function _model($file, $ClassName = NULL)
{
$file = str_replace(_PathTag, DIRECTORY_SEPARATOR, $file);
$ClassName = ($ClassName == NULL) ? $file : $ClassName;
$file = _Model . $file . '.php';
if(is_file($file))
{
include_once($file);
if(!class_exists($ClassName))
Amysql::AmysqlNotice($ClassName . ' 模型对象不存在');
$this -> DBConfig['ModelTag'] = $ModelTag = $ClassName . '_' . $this -> DBConfig['ConnectTag']; // 模型标识
if(!isset($this -> AmysqlModel[$ModelTag])) // 不存在模型
{
$this -> AmysqlModel[$ModelTag] = new $ClassName();
if(!isset($this -> DB -> DBS[$ModelTag])) $this -> DB -> DBConnect($this -> DBConfig); // 没连接就进行数据库连接
$this -> AmysqlModel[$ModelTag] -> MysqlConnect = $this -> DB -> DBS[$ModelTag]; // 模型使用的数据库连接
}
Return $this -> AmysqlModel[$ModelTag];
}
Amysql::AmysqlNotice($file . ' 模型文件不存在');
}
/**
* 获得相关文件数据(模板目录)
* @param string $file 文件名
* @return string 数据
*/
public function _file($file)
{
$file = str_replace(_PathTag, DIRECTORY_SEPARATOR, $file);
$file = _View . $file . '.php';
if(is_file($file))
Return file_get_contents($file);
Amysql::AmysqlNotice($file . ' 数据文件不存在');
}
/**
* 数据调试
* @param $data 数据
*/
public function _echo($data)
{
$this -> EchoData[] = $data;
}
/**
* 模板显示
*/
public function _view($file = null)
{
$this -> AmysqlTemplates -> _view($file);
// 信息调试输出
if (is_array($this -> AmysqlModel))
{
foreach ($this -> AmysqlModel as $key=>$val) // Sql调试
echo $this -> AmysqlModel[$key] -> SqlBug;
}
foreach ($this -
基于PHP的AMP-WEB应用开发MVC框架源码.zip
版权申诉
83 浏览量
2023-07-29
17:24:42
上传
评论
收藏 8KB ZIP 举报
毕业_设计
- 粉丝: 1922
- 资源: 1万+
最新资源
- 学生成绩管理系统-C++版本
- 吉林大学离散数学2笔记.pdf
- 通道处理过程的模拟通常涉及对通道处理机制的理解与实现.txt
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈