Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion initphp/core/controller/controller.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct() {
* @param int $status 0:错误信息|1:正确信息
* @param string $message 显示的信息
* @param array $data 传输的信息
* @param array $type 返回数据类型,json|xml|eval|jsonp
* @param string $type 返回数据类型,json|xml|eval|jsonp
* @return object
*/
public function ajax_return($status, $message = '', $data = array(), $type = 'json') {
Expand Down
6 changes: 3 additions & 3 deletions initphp/core/controller/filter.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class filterInit extends validateInit {
* @return string|array
*/
public function get_gp($value, $type = null, $isfilter = false) {
$temp = null;
$requestData = [];
if ($type == 'U' || $type == 'D') {
parse_str(file_get_contents('php://input'), $requestData);
}
Expand Down Expand Up @@ -57,7 +59,6 @@ public function get_gp($value, $type = null, $isfilter = false) {
* 安全过滤类-全局变量过滤
* 在Controller初始化的时候已经运行过该变量,对全局变量进行处理
* Controller中使用方法:$this->controller->filter()
* @return
*/
public function filter() {
if (is_array($_SERVER)) {
Expand All @@ -79,10 +80,9 @@ public function filter() {
* 安全过滤类-加反斜杠,放置SQL注入
* Controller中使用方法:$this->controller->filter_slashes(&$value)
* @param string $value 需要过滤的值
* @return string
*/
public static function filter_slashes(&$value) {
if (get_magic_quotes_gpc()) return false; //开启魔术变量
if (get_magic_quotes_gpc()) return ; //开启魔术变量
$value = (array) $value;
foreach ($value as $key => $val) {
if (is_array($val)) {
Expand Down
19 changes: 11 additions & 8 deletions initphp/core/dao/cache/cache.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function set($key, $value, $time = 0, $type = 'FILE') {
* DAO中使用方法:$this->dao->cache->get_cache($key,$type = 'FILE')
* @param string $key 缓存键值
* @param string $type 缓存类型
* @return
* @return mixed
*/
public function get($key, $type = 'FILE') {
$cache = $this->get_cache_handle($type);
Expand All @@ -52,7 +52,7 @@ public function get($key, $type = 'FILE') {
* DAO中使用方法:$this->dao->clear($key, $type = 'FILE')
* @param string $key 缓存键值
* @param string $type 缓存类型
* @return
* @return bool
*/
public function clear($key, $type = 'FILE') {
$cache = $this->get_cache_handle($type);
Expand All @@ -64,7 +64,7 @@ public function clear($key, $type = 'FILE') {
* 缓存类型
* DAO中使用方法:$this->dao->clear_all($type = 'FILE')
* @param string $type 缓存类型
* @return
* @return bool
*/
public function clear_all($type = 'FILE') {
$cache = $this->get_cache_handle($type);
Expand All @@ -75,7 +75,7 @@ public function clear_all($type = 'FILE') {
* 该接口获取缓存类接口
* 支持通过该函数直接调用缓存中的私用方法(除了set get clear clear_all之外)
* @param string $type 缓存类型
* @return
* @return filecacheInit|memcachedInit|mysqlcacheInit
*/
public function get_cache($type = 'MEM') {
return $this->get_cache_handle($type);
Expand All @@ -90,7 +90,7 @@ public function get_cache($type = 'MEM') {
* @param string $value 缓存数据
* @param string $time 缓存时间
* @param string $type 缓存类型
* @return
* @return null
*/
public function page_cache_start($key, $time = 0, $type = 'FILE') {
$this->page_cache_key = 'initphp_page_cache_' . $key;
Expand Down Expand Up @@ -119,7 +119,7 @@ public function page_cache_end() {
/**
* 缓存工厂-获取不同缓存类型的对象句柄
* @param string $type 缓存类型
* @return obj
* @return filecacheInit|memcachedInit|mysqlcacheInit
*/
private function get_cache_handle($type) {
$InitPHP_conf = InitPHP::getConfig(); //需要设置文件缓存目录
Expand Down Expand Up @@ -155,16 +155,19 @@ private function get_cache_handle($type) {
case 'APC' :
if (isset(cacheInit::$instance['apc'])) return cacheInit::$instance['apc'];
$filecache = $this->load_cache('apc.init.php', 'apcInit');
return $filecache;
break;

case 'XCACHE' :
if (isset(cacheInit::$instance['xcache'])) return cacheInit::$instance['xcache'];
$filecache = $this->load_cache('xcache.init.php', 'xcacheInit');
return $filecache;
break;
default:
case 'WINCACHE' :
if (isset(cacheInit::$instance['wincache'])) return cacheInit::$instance['wincache'];
$filecache = $this->load_cache('wincache.init.php', 'wincacheInit');
return $filecache;
break;
}
}
Expand All @@ -173,7 +176,7 @@ private function get_cache_handle($type) {
* 缓存工厂-加载不同缓存类文件
* @param string $file 缓存文件名
* @param string $class 缓存类名
* @return obj
* @return filecacheInit|memcachedInit|mysqlcacheInit
*/
private function load_cache($file, $class) {
if (cacheInit::$instance['require'][$file] !== TRUE) {
Expand Down
9 changes: 6 additions & 3 deletions initphp/core/dao/dao.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
class daoInit{

/**
* @var dbInit
* @var \dbInit
*/
public $db = NULL;

/**
* @var cacheInit
* @var \cacheInit
*/
public $cache = NULL;

/**
* @var nosqlInit
* @var \nosqlInit
*/
public $nosql = NULL;

/**
* 运行数据库
* 1. 初始化DB类 DAO中调用方法 $this->dao->db
* @return \dbInit
*/
public function run_db() {
if ($this->db == NULL) {
Expand All @@ -42,6 +43,7 @@ public function run_db() {
/**
* 运行缓存模型
* 1. 初始化cache类 DAO中调用方法 $this->dao->cache
* @return \cacheInit
*/
public function run_cache() {
if ($this->cache == NULL) {
Expand All @@ -55,6 +57,7 @@ public function run_cache() {
/**
* 运行nosql
* $this->getNosql()
* @return \nosqlInit
*/
public function run_nosql() {
if ($this->nosql == NULL) {
Expand Down
15 changes: 11 additions & 4 deletions initphp/core/dao/db/dbhandler.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
class dbhandlerInit {

protected static $dbArr = array(); // 存储 driver,db对象
/**
* @var mysqliInit|null
*/
protected $db = NULL; //DB引擎对象
protected $driverArr = array();
protected $dbModel = NULL; //DB配置模型,默认为default
Expand All @@ -22,7 +25,8 @@ class dbhandlerInit {
* 1. 可以在使用中通过$this->init_db('test')来切换数据库
* 2. 该函数是DB默认初始化入口
* 3. 支持多数据库链接,主从,随机分布式数据库
* @param obj $db
* @param string $db
* @return array
*/
public function init_db($db = '') {
$InitPHP_conf = InitPHP::getConfig();
Expand All @@ -38,13 +42,13 @@ public function init_db($db = '') {
$config = $InitPHP_conf['db'][$this->dbModel];
switch ($db_type) {
case 1: //主从模型
$key = floor(mt_rand(1,(count($config) - 2)));
$key = (int)(mt_rand(1,(count($config) - 2)));
self::$dbArr[$this->dbModel]['master']['link_id'] = $this->db_connect($config[0], $driver);
self::$dbArr[$this->dbModel]['salver']['link_id'] = $this->db_connect($config[$key], $driver);
break;

case 2: //随机模型
$key = floor(mt_rand(0,count($config) - 2));
$key = (int)(mt_rand(0,count($config) - 2));
self::$dbArr[$this->dbModel]['link_id'] = $this->db_connect($config[$key], $driver);
break;

Expand Down Expand Up @@ -109,6 +113,7 @@ protected function set_default_link_id() {
* 2. dirver 默认如果是mysql连接,可以不填写,如果填写了driver,则会使用不同的数据库类型,例如:mysqli
* 3. $this->db 是db类对象,单例
* @param array $config
* @param string $driver
* @return object
*/
private function db_connect($config, $driver) {
Expand Down Expand Up @@ -157,6 +162,7 @@ private function is_insert($sql) {
* Dao中使用方法:$this->dao->db->month_identify($tbl, $defaultId = '')
* @param string $tbl
* @param string $defaultId
* @return string
*/
public function month_identify($tbl, $defaultId = '') {
if (empty ( $defaultId )) {
Expand All @@ -176,6 +182,7 @@ public function month_identify($tbl, $defaultId = '') {
* @param int $num 数值
* @param string $tbl 模板前缀
* @param int $default 默认截取长度
* @return string
*/
public function num_identify($num, $tbl, $default = 1) {
$num = (string) $num;
Expand All @@ -195,7 +202,7 @@ public function num_identify($num, $tbl, $default = 1) {
* @param int $num
* @param string $tbl
* @param int $default
* @return
* @return int
*/
public function fmod_identify($num, $tbl, $default = 7) {
return $tbl . '_' . fmod($num, $default);
Expand Down
20 changes: 10 additions & 10 deletions initphp/core/dao/db/driver/dbbase.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,35 @@ abstract class dbbaseInit{
* @param string $password 数据库登录密码
* @param string $database 数据库
* @param string $charset 编码
* @param string $pconnect 是否持久链接
* @param int $pconnect 是否持久链接
*/
abstract protected function connect($host, $user, $password, $database, $charset = 'utf8', $pconnect = 0);

/**
* 抽象数据库执行语句
* @param string $sql SQL语句
* @return obj
* @return mixed
*/
abstract protected function query($sql);

/**
* 抽象数据库-结果集中的行数
* @param $result 结果集
* @param mixed $result 结果集
* @param int $num
* @return array
*/
abstract protected function result($result, $num=1);

/**
* 抽象数据库-从结果集中取得一行作为关联数组
* @param $result 结果集
* @param mixed $result 结果集
* @return array
*/
abstract protected function fetch_assoc($result);

/**
* 抽象数据库-从结果集中取得列信息并作为对象返回
* @param $result 结果集
* @param mixed $result 结果集
* @return array
*/
abstract protected function fetch_fields($result);
Expand All @@ -58,14 +59,14 @@ abstract protected function affected_rows();

/**
* 抽象数据库-结果集中的行数
* @param $result 结果集
* @param mixed $result 结果集
* @return int
*/
abstract protected function num_rows($result);

/**
* 抽象数据库-结果集中的字段数量
* @param $result 结果集
* @param mixed $result 结果集
* @return int
*/
abstract protected function num_fields($result);
Expand All @@ -78,14 +79,13 @@ abstract protected function insert_id();

/**
* 抽象数据库-释放结果内存
* @param obj $result 需要释放的对象
* @param mixed $result 需要释放的对象
*/
abstract protected function free_result($result);

/**
* 抽象数据库链接关闭
* @param string $sql SQL语句
* @return obj
* @return bool
*/
abstract protected function close();

Expand Down
17 changes: 9 additions & 8 deletions initphp/core/dao/db/driver/mysql.init.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class mysqlInit extends dbbaseInit{
* @param string $database 数据库
* @param string $charset 编码
* @param string $pconnect 是否持久链接
* @return obj
* @return resource
*/
public function connect($host, $user, $password, $database, $charset = 'utf8', $pconnect = 0) {
$link_id = ($pconnect == 0) ? mysql_connect($host, $user, $password, true) : mysql_pconnect($host, $user, $password);
Expand All @@ -34,15 +34,15 @@ public function connect($host, $user, $password, $database, $charset = 'utf8', $
/**
* SQL执行器
* @param string $sql SQL语句
* @return obj
* @return resource
*/
public function query($sql) {
return mysql_query($sql, $this->link_id);
}

/**
* 结果集中的行数
* @param $result 结果集
* @param resource $result
* @return array
*/
public function result($result, $num = 1) {
Expand All @@ -51,7 +51,7 @@ public function result($result, $num = 1) {

/**
* 从结果集中取得一行作为关联数组
* @param $result 结果集
* @param resource $result
* @return array
*/
public function fetch_assoc($result) {
Expand All @@ -60,7 +60,7 @@ public function fetch_assoc($result) {

/**
* 从结果集中取得列信息并作为对象返回
* @param $result 结果集
* @param resource $result
* @return array
*/
public function fetch_fields($result) {
Expand All @@ -69,7 +69,7 @@ public function fetch_fields($result) {

/**
* 结果集中的行数
* @param $result 结果集
* @param resource $result
* @return int
*/
public function num_rows($result) {
Expand All @@ -78,7 +78,7 @@ public function num_rows($result) {

/**
* 结果集中的字段数量
* @param $result 结果集
* @param resource $result
* @return int
*/
public function num_fields($result) {
Expand All @@ -87,7 +87,8 @@ public function num_fields($result) {

/**
* 释放结果内存
* @param obj $result 需要释放的对象
* @param resource $result
* @return bool
*/
public function free_result($result) {
return mysql_free_result($result);
Expand Down
Loading