一步步搭建自己的轻量级MVCphp框架-(三)一个国产轻量级框架Amysql源码分析(2) 进程

时间:2023-12-06 16:40:50

Amysql类 按照我的理解这就是框架的初始化

上代码

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;
include(_Amysql . 'AmysqlNotice.php');
exit();
} static public function filter(&$array, $function)
{
if (!is_array($array)) Return $array = $function($array);
foreach ($array as $key => $value)
(is_array($value) && $array[$key] = Amysql::filter($value, $function)) || $array[$key] = $function($value);
Return $array;
}
}

这个类包含一个公有属性AmysqlProcess和包括构造函数Amysql在内的三个函数

一、Amysql():这个函数是本类的构造函数,其实按照现在的写法就是__construct()。

  ① magic_quotes_runtime:作用就是将外部引入的特殊字符[单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)]加上反斜线给转移掉,但是这个在php5.3中已经废弃了,不太建议使用。

  ② error_reporting:设置PHP错误级别

    /*错误级别
    * fatal error致命错误:1
    * warning 警告错误:2
    * NOTICE 警告:8
    * 全部开启:11
    * 全部关闭:0
    */

  ③ 说明一下&& || 的写法,&&是要求这个标识符前后都得是真,||表示它的前后有一个是真就可以。

    当$Config['DebugPhp']为真的时候那么&&就会继续执行error_reporting(E_ALL),将错误级别设置成显示所有错误,又有||前面的已经执行,那么后面的就不会再执行了。当$Config['DebugPhp']为假的时候||前面的为假,所以就会执行后面的error_reporting(0)将错误显示级别设置成不显示错误。

二、AmysqlNotice():这个函数的作用就是显示错误提示

  ①在这里面使用AmysqlController类创建的对象AmysqlController并没有发现它有什么卵用。。

  ②引入一个外部的文件,AmysqlNotice.php,这个文件里面是一段HTML代码,用于显示错误提示,后面的exit是用来在错误提示输出后停止脚本运行。

  下面是错误提示的HTML代码,也没有什么分析的~O(∩_∩)O哈哈~  

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
body {margin: 0px;}
#confirm {background:rgba(125,125,125,0.4);filter:progid:DXImageTransform.Microsoft.Gradient(startColorstr=#40000000, endColorstr=#40000000);width:500px;margin:30px auto 0px auto;border:solid 1px #666;border-radius:3px;}
#confirm #inside {background:#FFFFFF;margin:5px;height:230px;border-radius:3px;}
#confirm #inside h1 {margin: 0px;font-family: Verdana, Geneva;font-size: 13px;padding:5px 10px;background-color: #f0f0f0;border:solid 1px #ddd;display: block;}
#confirm #inside #content {width: 300px;margin:25px auto 0px auto;line-height: 30px;font-size: 15px;font-family: Verdana, Geneva, sans-serif;}
</style>
</head>
<body>
<div id="confirm">
<div id="inside">
<h1>错误提示</h1>
<div id="content"><center><?php echo $notice ?></center></div>
</div>
</div>
</body>
</html>

三、filter(&$array, $function):这个函数的作用就是使用$function这个变量所代表的的函数将$array这个变量代表的值给进行转换。

  比如:

Amysql::filter($_GET, 'addslashes')

  这句代码就是使用addslashes()将$_GET变量的值进行转义。这个函数在内部将$array按照是否为数组来检测是否进行递归调用自己来进一步转换。

此上就是对Amysql类的分析,下一节将继续讲述AmysqlProcess总进程对象类