From 3704f593d5e1aa214c55de170185a344741d8f0d Mon Sep 17 00:00:00 2001 From: haixingdev Date: Fri, 12 Jun 2015 09:57:24 +0800 Subject: [PATCH 1/3] Update file.init.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原来的函数会由于权限问题死循环 --- initphp/library/file.init.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/initphp/library/file.init.php b/initphp/library/file.init.php index f808776..f4d933b 100644 --- a/initphp/library/file.init.php +++ b/initphp/library/file.init.php @@ -100,11 +100,8 @@ public function get_file_info($filename) { * @return */ public function create_dir($path) { - if (is_dir($path)) return false; - fileInit::create_dir(dirname($path)); - @mkdir($path); - @chmod($path, 0777); - return true; + if (is_dir($path)) return true; + return mkdir($path, 0777, true) && chmod($path, 0777); } /** @@ -140,4 +137,4 @@ public function del_dir($path) { return $succeed; } } -?> \ No newline at end of file +?> From 78ef04649c9cd790632ede3067eba6ff8a9455ef Mon Sep 17 00:00:00 2001 From: haixingdev Date: Fri, 12 Jun 2015 10:05:03 +0800 Subject: [PATCH 2/3] Update file.init.php --- initphp/library/file.init.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/initphp/library/file.init.php b/initphp/library/file.init.php index f4d933b..f5d3c3c 100644 --- a/initphp/library/file.init.php +++ b/initphp/library/file.init.php @@ -136,5 +136,4 @@ public function del_dir($path) { } return $succeed; } -} -?> +} From 1068943a1880ac17d7293e8d8a94858b688f76fd Mon Sep 17 00:00:00 2001 From: clover Date: Fri, 28 Apr 2017 15:41:40 +0800 Subject: [PATCH 3/3] fix bug of zhuli, lol. --- initphp/core/controller/controller.init.php | 2 +- initphp/core/controller/filter.init.php | 6 +- initphp/core/dao/cache/cache.init.php | 19 +++--- initphp/core/dao/dao.init.php | 9 ++- initphp/core/dao/db/dbhandler.init.php | 15 ++-- initphp/core/dao/db/driver/dbbase.init.php | 20 +++--- initphp/core/dao/db/driver/mysql.init.php | 17 ++--- initphp/core/dao/db/driver/mysqli.init.php | 30 ++++---- initphp/core/dao/db/sqlbuild.init.php | 1 + initphp/core/dao/nosql/driver/mongo.init.php | 23 ++++++- initphp/core/dao/nosql/driver/redis.init.php | 16 ++++- initphp/core/dao/nosql/nosql.init.php | 7 +- initphp/core/service/service.init.php | 4 +- initphp/core/util/debug.init.php | 11 ++- initphp/core/util/log.init.php | 1 - initphp/core/util/queue.init.php | 3 +- initphp/core/util/session.init.php | 1 - initphp/core/util/unittesting.init.php | 2 +- initphp/core/view/view.init.php | 32 +++++---- initphp/init/core.init.php | 27 ++++---- initphp/init/dispatcher.init.php | 3 + initphp/init/exception.init.php | 13 ++-- initphp/init/interceptor.init.php | 3 +- initphp/init/run.init.php | 24 ++++--- initphp/initphp.conf.php | 2 +- initphp/initphp.php | 72 +++++++++++--------- 26 files changed, 219 insertions(+), 144 deletions(-) diff --git a/initphp/core/controller/controller.init.php b/initphp/core/controller/controller.init.php index 17e1442..ee0ea1d 100644 --- a/initphp/core/controller/controller.init.php +++ b/initphp/core/controller/controller.init.php @@ -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') { diff --git a/initphp/core/controller/filter.init.php b/initphp/core/controller/filter.init.php index 17bdac4..ac0d1c7 100644 --- a/initphp/core/controller/filter.init.php +++ b/initphp/core/controller/filter.init.php @@ -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); } @@ -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)) { @@ -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)) { diff --git a/initphp/core/dao/cache/cache.init.php b/initphp/core/dao/cache/cache.init.php index f732fba..ce79e9b 100644 --- a/initphp/core/dao/cache/cache.init.php +++ b/initphp/core/dao/cache/cache.init.php @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; @@ -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(); //需要设置文件缓存目录 @@ -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; } } @@ -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) { diff --git a/initphp/core/dao/dao.init.php b/initphp/core/dao/dao.init.php index 741615e..9c97b34 100644 --- a/initphp/core/dao/dao.init.php +++ b/initphp/core/dao/dao.init.php @@ -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) { @@ -42,6 +43,7 @@ public function run_db() { /** * 运行缓存模型 * 1. 初始化cache类 DAO中调用方法 $this->dao->cache + * @return \cacheInit */ public function run_cache() { if ($this->cache == NULL) { @@ -55,6 +57,7 @@ public function run_cache() { /** * 运行nosql * $this->getNosql() + * @return \nosqlInit */ public function run_nosql() { if ($this->nosql == NULL) { diff --git a/initphp/core/dao/db/dbhandler.init.php b/initphp/core/dao/db/dbhandler.init.php index e81976c..503d256 100644 --- a/initphp/core/dao/db/dbhandler.init.php +++ b/initphp/core/dao/db/dbhandler.init.php @@ -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 @@ -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(); @@ -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; @@ -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) { @@ -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 )) { @@ -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; @@ -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); diff --git a/initphp/core/dao/db/driver/dbbase.init.php b/initphp/core/dao/db/driver/dbbase.init.php index 23bdd0a..a160014 100644 --- a/initphp/core/dao/db/driver/dbbase.init.php +++ b/initphp/core/dao/db/driver/dbbase.init.php @@ -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); @@ -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); @@ -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(); diff --git a/initphp/core/dao/db/driver/mysql.init.php b/initphp/core/dao/db/driver/mysql.init.php index 3a12f86..184d594 100644 --- a/initphp/core/dao/db/driver/mysql.init.php +++ b/initphp/core/dao/db/driver/mysql.init.php @@ -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); @@ -34,7 +34,7 @@ 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); @@ -42,7 +42,7 @@ public function query($sql) { /** * 结果集中的行数 - * @param $result 结果集 + * @param resource $result * @return array */ public function result($result, $num = 1) { @@ -51,7 +51,7 @@ public function result($result, $num = 1) { /** * 从结果集中取得一行作为关联数组 - * @param $result 结果集 + * @param resource $result * @return array */ public function fetch_assoc($result) { @@ -60,7 +60,7 @@ public function fetch_assoc($result) { /** * 从结果集中取得列信息并作为对象返回 - * @param $result 结果集 + * @param resource $result * @return array */ public function fetch_fields($result) { @@ -69,7 +69,7 @@ public function fetch_fields($result) { /** * 结果集中的行数 - * @param $result 结果集 + * @param resource $result * @return int */ public function num_rows($result) { @@ -78,7 +78,7 @@ public function num_rows($result) { /** * 结果集中的字段数量 - * @param $result 结果集 + * @param resource $result * @return int */ public function num_fields($result) { @@ -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); diff --git a/initphp/core/dao/db/driver/mysqli.init.php b/initphp/core/dao/db/driver/mysqli.init.php index 31db842..f718582 100644 --- a/initphp/core/dao/db/driver/mysqli.init.php +++ b/initphp/core/dao/db/driver/mysqli.init.php @@ -20,8 +20,8 @@ class mysqliInit extends dbbaseInit{ * @param string $password 数据库登录密码 * @param string $database 数据库 * @param string $charset 编码 - * @param string $pconnect 是否持久链接 - * @return obj + * @param int $pconnect 是否持久链接 + * @return \mysqli */ public function connect($host, $user, $password, $database, $charset = 'utf8', $pconnect = 0) { $port = 3306; //设置默认值 @@ -30,7 +30,7 @@ public function connect($host, $user, $password, $database, $charset = 'utf8', $ $host = $arr[0]; $port = $arr[1]; } - $link_id = ($pconnect == 0) ? mysqli_connect($host, $user, $password, $database, $port) : mysqli_pconnect($host, $user, $password, $database, $port); + $link_id = ($pconnect == 0) ? mysqli_connect($host, $user, $password, $database, $port) : mysqli_connect("p:$host", $user, $password, $database, $port); if (!$link_id) InitPHP::initError("mysqli connect error"); mysqli_query($link_id, 'SET NAMES ' . $charset); return $link_id; @@ -38,8 +38,11 @@ public function connect($host, $user, $password, $database, $charset = 'utf8', $ /** * SQL执行器 + * For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries, mysqli_query() will return a mysqli_result object. + * For other successful queries mysqli_query() will return TRUE. + * Returns FALSE on failure. * @param string $sql SQL语句 - * @return obj + * @return mysqli_result|bool */ public function query($sql) { return mysqli_query($this->link_id, $sql); @@ -47,16 +50,17 @@ public function query($sql) { /** * 结果集中的行数 - * @param $result 结果集 - * @return array + * @param mysqli $result + * @param $num + * @return mysqli_result|bool */ public function result($result, $num=1) { - return mysqli_result($result, $num); + return mysqli_store_result($result); } /** * 从结果集中取得一行作为关联数组 - * @param $result 结果集 + * @param mysqli_result $result 结果集 * @return array */ public function fetch_assoc($result) { @@ -65,7 +69,7 @@ public function fetch_assoc($result) { /** * 从结果集中取得列信息并作为对象返回 - * @param $result 结果集 + * @param mysqli_result $result * @return array */ public function fetch_fields($result) { @@ -74,7 +78,7 @@ public function fetch_fields($result) { /** * 结果集中的行数 - * @param $result 结果集 + * @param mysqli_result $result * @return int */ public function num_rows($result) { @@ -83,7 +87,7 @@ public function num_rows($result) { /** * 结果集中的字段数量 - * @param $result 结果集 + * @param mysqli_result $result * @return int */ public function num_fields($result) { @@ -92,10 +96,10 @@ public function num_fields($result) { /** * 释放结果内存 - * @param obj $result 需要释放的对象 + * @param \mysqli_result $result 需要释放的对象 */ public function free_result($result) { - return mysqli_free_result($result); + mysqli_free_result($result); } /** diff --git a/initphp/core/dao/db/sqlbuild.init.php b/initphp/core/dao/db/sqlbuild.init.php index 03a55b4..d4a9ee0 100644 --- a/initphp/core/dao/db/sqlbuild.init.php +++ b/initphp/core/dao/db/sqlbuild.init.php @@ -168,6 +168,7 @@ public function build_implode($val, $iskey = 0) { * DAO中使用方法:$this->dao->db->build_key($data, $fields) * @param array $data 例如:array("username" => 'asdasd') * @param string $fields 例如:"username,password" + * @return array */ public function build_key($data, $fields) { $fields = explode(',', $fields); diff --git a/initphp/core/dao/nosql/driver/mongo.init.php b/initphp/core/dao/nosql/driver/mongo.init.php index 11b409b..65c0b0f 100644 --- a/initphp/core/dao/nosql/driver/mongo.init.php +++ b/initphp/core/dao/nosql/driver/mongo.init.php @@ -11,8 +11,17 @@ ***********************************************************************************/ class mongoInit { + /** + * @var Mongo + */ private $mongo; //mongo对象 + /** + * @var MongoDB + */ private $db; //db mongodb对象数据库 + /** + * @var MongoCollection + */ private $collection; //集合,相当于数据表 /** @@ -26,7 +35,7 @@ class mongoInit { * ‘password’=> '123456' 数据库密码 * ) * Enter description here ... - * @param unknown_type $config + * @param array $config */ public function init($config = array()) { if ($config['server'] == '') $config['server'] = '127.0.0.1'; @@ -43,6 +52,7 @@ public function init($config = array()) { /** * 选择一个集合,相当于选择一个数据表 * @param string $collection 集合名称 + * @return bool */ public function selectCollection($collection) { return $this->collection = $this->db->selectCollection($collection); @@ -52,6 +62,7 @@ public function selectCollection($collection) { * 新增数据 * @param array $data 需要新增的数据 例如:array('title' => '1000', 'username' => 'xcxx') * @param array $option 参数 + * @return bool */ public function insert($data, $option = array()) { return $this->collection->insert($data, $option); @@ -61,6 +72,7 @@ public function insert($data, $option = array()) { * 批量新增数据 * @param array $data 需要新增的数据 例如:array(0=>array('title' => '1000', 'username' => 'xcxx')) * @param array $option 参数 + * @return bool */ public function batchInsert($data, $option = array()) { return $this->collection->batchInsert($data, $option); @@ -70,6 +82,7 @@ public function batchInsert($data, $option = array()) { * 保存数据,如果已经存在在库中,则更新,不存在,则新增 * @param array $data 需要新增的数据 例如:array(0=>array('title' => '1000', 'username' => 'xcxx')) * @param array $option 参数 + * @return array|boolean */ public function save($data, $option = array()) { return $this->collection->save($data, $option); @@ -79,6 +92,7 @@ public function save($data, $option = array()) { * 根据条件移除 * @param array $query 条件 例如:array(('title' => '1000')) * @param array $option 参数 + * @return bool|array */ public function remove($query, $option = array()) { return $this->collection->remove($query, $option); @@ -89,6 +103,7 @@ public function remove($query, $option = array()) { * @param array $query 条件 例如:array(('title' => '1000')) * @param array $data 需要更新的数据 例如:array(0=>array('title' => '1000', 'username' => 'xcxx')) * @param array $option 参数 + * @return boolean */ public function update($query, $data, $option = array()) { return $this->collection->update($query, $data, $option); @@ -98,6 +113,7 @@ public function update($query, $data, $option = array()) { * 根据条件查找一条数据 * @param array $query 条件 例如:array(('title' => '1000')) * @param array $fields 参数 + * @return array|null */ public function findOne($query, $fields = array()) { return $this->collection->findOne($query, $fields); @@ -107,9 +123,10 @@ public function findOne($query, $fields = array()) { * 根据条件查找多条数据 * @param array $query 查询条件 * @param array $sort 排序条件 array('age' => -1, 'username' => 1) - * @param int $limit 页面 + * @param int $skip 页面 * @param int $limit 查询到的数据条数 - * @param array $fields返回的字段 + * @param array $fields 返回的字段 + * @return array */ public function find($query, $sort = array(), $skip = 0, $limit = 0, $fields = array()) { $cursor = $this->collection->find($query, $fields); diff --git a/initphp/core/dao/nosql/driver/redis.init.php b/initphp/core/dao/nosql/driver/redis.init.php index c70f38c..c98b76d 100644 --- a/initphp/core/dao/nosql/driver/redis.init.php +++ b/initphp/core/dao/nosql/driver/redis.init.php @@ -10,7 +10,9 @@ * $Dtime:2013-5-29 ***********************************************************************************/ class redisInit { - + /** + * @var \Redis + */ private $redis; //redis对象 /** @@ -20,6 +22,7 @@ class redisInit { * 'port' => '6379' 端口号 * ) * @param array $config + * @return \Redis */ public function init($config = array()) { if ($config['server'] == '') $config['server'] = '127.0.0.1'; @@ -34,6 +37,7 @@ public function init($config = array()) { * @param string $key KEY名称 * @param string|array $value 获取得到的数据 * @param int $timeOut 时间 + * @return bool */ public function set($key, $value, $timeOut = 0) { $value = json_encode($value, TRUE); @@ -45,6 +49,7 @@ public function set($key, $value, $timeOut = 0) { /** * 通过KEY获取数据 * @param string $key KEY名称 + * @return array|null */ public function get($key) { $result = $this->redis->get($key); @@ -54,13 +59,15 @@ public function get($key) { /** * 删除一条数据 * @param string $key KEY名称 + * @return bool */ public function delete($key) { - return $this->redis->delete($key); + return $this->redis->del($key); } /** * 清空数据 + * @return bool */ public function flushAll() { return $this->redis->flushAll(); @@ -71,6 +78,7 @@ public function flushAll() { * @param string $key KEY名称 * @param string|array $value 获取得到的数据 * @param bool $right 是否从右边开始入 + * @return bool */ public function push($key, $value ,$right = true) { $value = json_encode($value); @@ -81,6 +89,7 @@ public function push($key, $value ,$right = true) { * 数据出队列 * @param string $key KEY名称 * @param bool $left 是否从左边开始出数据 + * @return \stdClass */ public function pop($key , $left = true) { $val = $left ? $this->redis->lPop($key) : $this->redis->rPop($key); @@ -90,6 +99,7 @@ public function pop($key , $left = true) { /** * 数据自增 * @param string $key KEY名称 + * @return int */ public function increment($key) { return $this->redis->incr($key); @@ -98,6 +108,7 @@ public function increment($key) { /** * 数据自减 * @param string $key KEY名称 + * @return int */ public function decrement($key) { return $this->redis->decr($key); @@ -106,6 +117,7 @@ public function decrement($key) { /** * key是否存在,存在返回ture * @param string $key KEY名称 + * @return bool */ public function exists($key) { return $this->redis->exists($key); diff --git a/initphp/core/dao/nosql/nosql.init.php b/initphp/core/dao/nosql/nosql.init.php index 82591b6..b7ebbe6 100644 --- a/initphp/core/dao/nosql/nosql.init.php +++ b/initphp/core/dao/nosql/nosql.init.php @@ -17,6 +17,8 @@ class nosqlInit { /** * 获取Nosql对象 * @param string $type + * @param string $server + * @return mongoInit|redisInit */ public function init($type = 'MONGO', $server = 'default') { $InitPHP_conf = InitPHP::getConfig(); //需要设置文件缓存目录 @@ -31,8 +33,9 @@ public function init($type = 'MONGO', $server = 'default') { nosqlInit::$instance[$instance_name] = $mongo; return $mongo; break; - + case 'REDIS' : + default: $instance_name = 'redis_' . $server; if (isset(nosqlInit::$instance[$instance_name])) return nosqlInit::$instance[$instance_name]; $redis = $this->load_nosql('redis.init.php', 'redisInit', $server); @@ -48,7 +51,7 @@ public function init($type = 'MONGO', $server = 'default') { * @param string $file 缓存文件名 * @param string $class 缓存类名 * @param String $server 服务器 - * @return obj + * @return mongoInit|redisInit */ private function load_nosql($file, $class, $server) { if (nosqlInit::$instance['require'][$file] != TRUE) { diff --git a/initphp/core/service/service.init.php b/initphp/core/service/service.init.php index 5e45f5a..06c6f82 100644 --- a/initphp/core/service/service.init.php +++ b/initphp/core/service/service.init.php @@ -15,7 +15,7 @@ class serviceInit { * Service中使用方法:$this->service->parse_data($field, $data) * @param array $field 可信任字段 array(array('field', 'int')) * @param array $data 传入的参数 - * @return object + * @return array */ public function parse_data($field, $data) { $field = (array) $field; @@ -39,7 +39,7 @@ public function parse_data($field, $data) { * @param int $status 返回参数状态 * @param string $msg 提示信息 * @param string $data 传递的参数 - * @return object + * @return array */ public function return_msg($status, $msg, $data = '') { return array($status, $msg, $data); diff --git a/initphp/core/util/debug.init.php b/initphp/core/util/debug.init.php index 5ead895..65e3bc5 100644 --- a/initphp/core/util/debug.init.php +++ b/initphp/core/util/debug.init.php @@ -17,7 +17,6 @@ class debugInit { * 使用方法:$this->getUtil('debug')->dump($data, $isexit = 0) * @param string $data 参数 * @param int $isexit 是否跳出 - * @return */ public function dump($data, $isexit = 0) { @@ -26,7 +25,7 @@ public function dump($data, $isexit = 0) { $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); - $output = '
' . $label . htmlspecialchars($output, ENT_QUOTES) . '
'; + $output = '
' . htmlspecialchars($output, ENT_QUOTES) . '
'; } echo $output; if ($isexit) exit(); @@ -37,7 +36,7 @@ public function dump($data, $isexit = 0) { * debug-BUG调试工具-程序标记 * 使用方法:$this->getUtil('debug')->mark($name) * @param string $name 开始和结束时间的标记名称 - * @return + * @return array */ public function mark($name) { self::$mark_arr['time'][$name][] = microtime(TRUE); @@ -49,8 +48,8 @@ public function mark($name) { * debug-BUG调试工具-计算程序段使用的时间 * 使用方法:$this->getUtil('debug')->use_time($name, $decimal = 6) * @param string $name 开始和结束时间的标记名称 - * @param string $decimal 小数位数 - * @return + * @param int $decimal 小数位数 + * @return string */ public function use_time($name, $decimal = 6) { if (!isset(self::$mark_arr['time'][$name][1])) { @@ -63,7 +62,7 @@ public function use_time($name, $decimal = 6) { * debug-BUG调试工具-计算程序段计算内存使用峰值 * 使用方法:$this->getUtil('debug')->use_memory($name) * @param string $name 开始和结束时间的标记名称 - * @return + * @return string */ public function use_memory($name) { if (!isset(self::$mark_arr['memory'][$name][1])) { diff --git a/initphp/core/util/log.init.php b/initphp/core/util/log.init.php index 43ef682..0524029 100644 --- a/initphp/core/util/log.init.php +++ b/initphp/core/util/log.init.php @@ -17,7 +17,6 @@ class logInit { * 使用方法:$this->getUtil('log')->write('日志内容'); * @param string $message 日志信息 * @param string $log_type 日志类型 ERROR WARN DEBUG INFO - * @return */ public function write($message, $log_type = 'DEBUG') { $log_path = $this->get_file_log_name(); diff --git a/initphp/core/util/queue.init.php b/initphp/core/util/queue.init.php index 72c7e0a..daf380a 100644 --- a/initphp/core/util/queue.init.php +++ b/initphp/core/util/queue.init.php @@ -15,7 +15,8 @@ class queueInit { /** * 队列-设置值 * 使用方法:$this->getUtil('queue')->set('ccccccc'); - * @return string + * @param $val + * @return string */ public function set($val) { array_unshift(self::$queue, $val); diff --git a/initphp/core/util/session.init.php b/initphp/core/util/session.init.php index 8633172..d741911 100644 --- a/initphp/core/util/session.init.php +++ b/initphp/core/util/session.init.php @@ -59,7 +59,6 @@ public function del($key) { /** * Session-清空session * 使用方法:$this->getUtil('session')->clear(); - * @return */ public function clear() { if (!session_id()) $this->start(); diff --git a/initphp/core/util/unittesting.init.php b/initphp/core/util/unittesting.init.php index dd4cc4e..d76f84b 100644 --- a/initphp/core/util/unittesting.init.php +++ b/initphp/core/util/unittesting.init.php @@ -19,7 +19,6 @@ class unittestingInit { /** * 系统自动加载InitPHP类库 * @param string $class_name 类名称 - * @param string $type 类所属类型 * @return object */ public function run($file = '') { @@ -61,6 +60,7 @@ public function add_data($function_param, $forecast_result, $type = '=') { * @return object */ public function test($function) { + $result_test = false; $InitPHP_conf = InitPHP::getConfig(); $obj = $this->get_service_obj(); if ($obj) { diff --git a/initphp/core/view/view.init.php b/initphp/core/view/view.init.php index 434c556..61edb11 100644 --- a/initphp/core/view/view.init.php +++ b/initphp/core/view/view.init.php @@ -18,6 +18,9 @@ class templateInit { private $template_tag_right = '}-->'; //右标签 private $is_compile = true; //是否需要每次编译 private $driver_config; + /** + * @var \defaultInit|\simpleInit + */ private static $driver = NULL; //定义默认的一个模板编译驱动模型 /** @@ -56,7 +59,7 @@ public function set_template_config($config) { /** * 模板编译-模板类入口函数 * 1. 获取模板,如果模板未编译,则编译 - * @param string $filename 文件名称,例如:test,不带文件.htm类型 + * @param string $file_name 文件名称,例如:test,不带文件.htm类型 * @return string */ protected function template_run($file_name) { @@ -74,8 +77,8 @@ protected function template_run($file_name) { /** * 模板编译-读取静态模板 - * @param string $filename 文件名称,例如:test,不带文件.htm类型 - * @return + * @param string $template_file_name 文件名称,例如:test,不带文件.htm类型 + * @return string */ private function read_template($template_file_name) { if (!file_exists($template_file_name)) InitPHP::initError($template_file_name. ' is not exist!'); @@ -84,9 +87,8 @@ private function read_template($template_file_name) { /** * 模板编译-编译模板 - * @param string $filename 文件名称,例如:test,不带文件.htm类型 + * @param string $compile_file_name 文件名称,例如:test,不带文件.htm类型 * @param string $str 写入编译文件的数据 - * @return */ private function compile_template($compile_file_name, $str) { if (($path = dirname($compile_file_name)) !== $this->template_c_path) { //自动创建文件夹 @@ -100,8 +102,8 @@ private function compile_template($compile_file_name, $str) { /** * 模板编译-通过传入的filename,获取要编译的静态页面和生成编译文件的文件名 - * @param string $filename 文件名称,例如:test,不带文件.htm类型 - * @return + * @param string $file_name 文件名称,例如:test,不带文件.htm类型 + * @return array */ private function get_file_name($file_name) { return array( @@ -112,7 +114,7 @@ private function get_file_name($file_name) { /** * 模板编译-检测模板目录和编译目录是否可写 - * @return + * @return bool */ private function check_path() { if (!is_dir($this->template_path) || !is_readable($this->template_path)) InitPHP::initError('template path is unread!'); @@ -123,6 +125,7 @@ private function check_path() { /** * 模板编译-编译文件-头部版本信息 * @param string $str 模板文件数据 + * @param string $template_file_name * @return string */ private function compile_version($str, $template_file_name) { @@ -169,8 +172,8 @@ private function layout_path($template_name) { /** * 模板编译-获取不同 - * @param string $template_name 模板名称 - * @return string + * @param string $driver 模板名称 + * @return \defaultInit|\simpleInit */ private function get_driver($driver) { $diver_path = 'driver/' . $driver . '.init.php'; @@ -187,13 +190,11 @@ private function get_driver($driver) { /** * 创建目录 * @param string $path 目录 - * @return + * @return bool */ private function create_dir($path) { if (is_dir($path)) return false; - $this->create_dir(dirname($path)); - @mkdir($path); - @chmod($path, 0777); + mkdir($path, 0777, true); return true; } @@ -263,6 +264,7 @@ public function get_tpl() { * 1. 在Controller中需要显示模板,就必须调用该函数 * 2. 模板解析可以设置 $InitPHP_conf['isviewfilter'] 值,对变量进行过滤 * Controller中使用方法:$this->view->display(); + * @param string $template * @return array */ public function display($template = '') { @@ -304,7 +306,7 @@ private function parse_template_arr(array $arr) { /** * 模板-模板变量输出过滤 - * @param array $arr 视图存放器数组 + * @param array $value 视图存放器数组 * @return array */ private function out_put(&$value) { diff --git a/initphp/init/core.init.php b/initphp/init/core.init.php index e921046..887c615 100644 --- a/initphp/init/core.init.php +++ b/initphp/init/core.init.php @@ -35,6 +35,7 @@ public function __construct() { * 使用方法:$this->load($class_name, $type) * @param string $class_name 类名称 * @param string $type 类别 + * @return mixed */ public function load($class_name, $type) { $class_path = $this->get_class_path($class_name, $type); @@ -54,7 +55,7 @@ public function load($class_name, $type) { * 1. 通过$this->getLibrary($class) 就可以加载Library下面的类 * 2. 单例模式-通过load核心函数加载 * 全局使用方法:$this->getLibrary($class) - * @param string $class_name 类名称 + * @param string $class 类名称 * @return object */ public function getLibrary($class) { @@ -66,7 +67,7 @@ public function getLibrary($class) { * 1. 通过$this->getUtil($class) 就可以加载Util下面的类 * 2. 单例模式-通过load核心函数加载 * 全局使用方法:$this->getUtil($class) - * @param string $class_name 类名称 + * @param string $class 类名称 * @return object */ public function getUtil($class) { @@ -105,6 +106,7 @@ public function getNosql() { * 使用Mongo,你的服务器端需要安装Mongo * 需要在配置文件中配置$InitPHP_conf['mongo'][服务器server] * 如果多个mongo分布,则直接可以改变$server就可以切换 + * @param string $server * @return mongoInit */ public function getMongo($server = 'default') { @@ -121,6 +123,7 @@ public function getMongo($server = 'default') { * 使用Redis,你的服务器端需要安装Redis * 需要在配置文件中配置$InitPHP_conf['redis'][服务器server] * 如果多个redis分布,则直接可以改变$server就可以切换 + * @param string $server * @return redisInit */ public function getRedis($server = 'default') { @@ -134,41 +137,41 @@ public function getRedis($server = 'default') { /** * 获取m * 全局使用方法:$this->getM() - * @return + * @return string */ public static function getM() { $InitPHP_conf = InitPHP::getConfig(); if ($InitPHP_conf['ismodule'] === false) return ''; - if ($_GET['m'] == '') return $InitPHP_conf['controller']['default_module']; - return $_GET['m']; + if (empty($_GET['m'])) return $InitPHP_conf['controller']['default_module']; + return (string)$_GET['m']; } /** * 获取c * 全局使用方法:$this->getC() - * @return + * @return string */ public static function getC() { $InitPHP_conf = InitPHP::getConfig(); - if ($_GET['c'] == '') return $InitPHP_conf['controller']['default_controller']; - return $_GET['c']; + if (empty($_GET['c'])) return $InitPHP_conf['controller']['default_controller']; + return (string)$_GET['c']; } /** * 获取a * 全局使用方法:$this->getA() - * @return + * @return string */ public static function getA() { $InitPHP_conf = InitPHP::getConfig(); - if ($_GET['a'] == '') return $InitPHP_conf['controller']['default_action']; - return $_GET['a']; + if (empty($_GET['a'])) return $InitPHP_conf['controller']['default_action']; + return (string)$_GET['a']; } /** * 注册到框架全局可用变量 * @param string $name 变量名称 - * @param val $value 变量值 + * @param string $value 变量值 */ public function register_global($name, $value) { self::$instance['global'][$name] = $value; diff --git a/initphp/init/dispatcher.init.php b/initphp/init/dispatcher.init.php index 0a8c959..ce45ab7 100644 --- a/initphp/init/dispatcher.init.php +++ b/initphp/init/dispatcher.init.php @@ -67,6 +67,7 @@ private function getRequest() { * 1. 解析index.php/user/new/username * 2. 解析成数组,array() * @param string $request + * @return array */ private function parsePathUri($request) { $InitPHP_conf = InitPHP::getConfig(); @@ -108,6 +109,7 @@ private function parsePathUri($request) { * 1. 解析index.php/user/new/username/?id=100 * 2. 解析成数组,array() * @param string $request + * @return array */ private function parseRewriteUri($request) { $InitPHP_conf = InitPHP::getConfig(); @@ -132,6 +134,7 @@ private function parseRewriteUri($request) { * 1. 解析user-add.htm?uid=100 * 2. 解析成数组,array() * @param string $request + * @return array */ private function parseHtmlUri($request) { $InitPHP_conf = InitPHP::getConfig(); diff --git a/initphp/init/exception.init.php b/initphp/init/exception.init.php index 502c068..57701d3 100644 --- a/initphp/init/exception.init.php +++ b/initphp/init/exception.init.php @@ -14,11 +14,12 @@ class exceptionInit extends Exception{ /** * 命令行运行,异常模板 + * @param \Exception */ - public static function cliErrorTpl($e) { + public static function cliErrorTpl(\Exception $e) { $InitPHP_conf = InitPHP::getConfig(); $msg = $e->message; - $mainErrorCode = $e->getLineCode($e->getFile(), $e->getLine()); + $mainErrorCode = self::getLineCode($e->getFile(), $e->getLine()); self::_recordError($msg,$e->getFile(),$e->getLine(),trim($mainErrorCode)); //如果debug关闭,则不显示debug错误信息 $trace = $e->getTrace(); @@ -43,9 +44,10 @@ public static function cliErrorTpl($e) { /** * 异常模板 - * @param $e + * @param \Exception $e */ - public static function errorTpl($e) { + public static function errorTpl(\Exception $e) { + $sqlTraceHtml = ''; $InitPHP_conf = InitPHP::getConfig(); $msg = $e->message; $mainErrorCode = self::getLineCode($e->getFile(), $e->getLine()); @@ -142,6 +144,7 @@ private static function getLineCode($file,$line) { break; } } + return 0; } /** * record error log @@ -151,7 +154,7 @@ private static function getLineCode($file,$line) { * @param string $code */ private static function _recordError($msg, $file, $line, $code){ - $string.='['.date('Y-m-d h:i:s').']msg:'.$msg.';file:'.$file.';line:'.$line.';code:'.$code.''; + $string ='['.date('Y-m-d h:i:s').']msg:'.$msg.';file:'.$file.';line:'.$line.';code:'.$code.''; InitPHP::log($string, ERROR); //记录日志 } } \ No newline at end of file diff --git a/initphp/init/interceptor.init.php b/initphp/init/interceptor.init.php index d1bfcfa..af3dfcc 100644 --- a/initphp/init/interceptor.init.php +++ b/initphp/init/interceptor.init.php @@ -40,7 +40,8 @@ public function postHandle() { /** * 具体解析 - * @param unknown_type $isPre + * @param bool $isPre + * @return bool */ private function parse($isPre = true) { $InitPHP_conf = InitPHP::getConfig(); diff --git a/initphp/init/run.init.php b/initphp/init/run.init.php index e21ed89..6f491dd 100644 --- a/initphp/init/run.init.php +++ b/initphp/init/run.init.php @@ -32,7 +32,7 @@ class runInit { * 3. 运行前置Action * 4. 运行正常Action * 5. 运行后置Action - * @return file + * @return string file */ public function run() { $InitPHP_conf = InitPHP::getConfig(); //全局配置 @@ -116,7 +116,6 @@ private function checkRequest() { * 3. 检测方法是否存在,不存在则运行默认的 * 4. 运行函数 * @param object $controller 控制器对象 - * @return file */ private function run_action($controller) { $action = trim($_GET['a']); @@ -133,7 +132,7 @@ private function run_action($controller) { * 白名单参数支持指定GET POST PUT DEL 等HTTP METHOD操作 * 白名单参数:array('test', 'user|post') * @param object $controller 控制器对象 - * @return file + * @return array */ private function parseWhiteList($initphp_list) { $whiteList = $methodList = array(); @@ -157,12 +156,13 @@ private function parseWhiteList($initphp_list) { * 1. 检测方法是否存在,不存在则运行默认的 * 2. 运行函数 * @param object $controller 控制器对象 - * @return file + * @return bool */ private function run_before_action($controller) { $before_action = $this->default_before_action . $this->action_postfix; if (!method_exists($controller, $before_action)) return false; $controller->$before_action(); + return true; } /** @@ -170,12 +170,13 @@ private function run_before_action($controller) { * 1. 检测方法是否存在,不存在则运行默认的 * 2. 运行函数 * @param object $controller 控制器对象 - * @return file + * @return bool */ private function run_after_action($controller) { $after_action = $this->default_after_action . $this->action_postfix; if (!method_exists($controller, $after_action)) return false; $controller->$after_action(); + return true; } /** @@ -230,16 +231,21 @@ public function init2Ehandle(){ set_error_handler(array($this,'handleError'),error_reporting()); } - /* - *设置异常处理函数,写入日志文件 + /** + * 设置异常处理函数,写入日志文件 + * @param $exception */ public function handleException($exception){ restore_exception_handler(); exceptionInit::errorTpl($exception); } - /* - *设置PHP错误处理回调函数,写入日志文件 + /** + * 设置PHP错误处理回调函数,写入日志文件 + * @param $errorCode + * @param string $msg + * @param string $errorFile + * @param int $errorLine */ public function handleError($errorCode, $msg = '', $errorFile = 'unkwon', $errorLine = 0){ $InitPHP_conf = InitPHP::getConfig(); diff --git a/initphp/initphp.conf.php b/initphp/initphp.conf.php index fa7d092..23b1763 100644 --- a/initphp/initphp.conf.php +++ b/initphp/initphp.conf.php @@ -8,7 +8,7 @@ * Author:zhuli Dtime:2014-11-25 ***********************************************************************************/ /* 框架全局配置常量 */ -define('INITPHP_PATH', dirname(__FILE__)); +define('INITPHP_PATH', __DIR__); define('IS_INITPHP', 1); error_reporting(E_ERROR | E_PARSE); /* 框架全局配置变量 */ diff --git a/initphp/initphp.php b/initphp/initphp.php index 4f0015a..3c9b530 100644 --- a/initphp/initphp.php +++ b/initphp/initphp.php @@ -7,10 +7,10 @@ *------------------------------------------------------------------------------- * Author:zhuli Dtime:2014-11-25 ***********************************************************************************/ -require_once('initphp.conf.php'); //导入框架配置类 -require_once('init/core.init.php'); //导入核心类文件 -require_once('init/exception.init.php'); //导入核心类文件 -require_once('init/interceptorInterface.init.php'); //导入拦截器接口 +require_once(__DIR__.'/initphp.conf.php'); //导入框架配置类 +require_once(__DIR__.'/init/core.init.php'); //导入核心类文件 +require_once(__DIR__.'/init/exception.init.php'); //导入核心类文件 +require_once(__DIR__.'/init/interceptorInterface.init.php'); //导入拦截器接口 define("ERROR", "ERROR"); define("WARN", "WARN"); define("DEBUG", "DEBUG"); @@ -25,6 +25,7 @@ class InitPHP extends coreInit { private static function isDebug() { $InitPHP_conf = InitPHP::getConfig(); if (isset($InitPHP_conf['is_debug']) && $InitPHP_conf['is_debug'] == true && isset($InitPHP_conf['show_all_error']) && $InitPHP_conf['show_all_error'] == true) { + ini_set('display_errors', 'On'); error_reporting(E_ALL^E_NOTICE); } } @@ -57,7 +58,8 @@ public static function init() { * 命令行模式运行php * 1. 例如:/usr/lib/php /usr/local/web/www/index.php index test sq * 2. index 控制器名称 test Action名称 sql controller/文件夹下的文件名称 - * 3. 全局使用方法:InitPHP::cli_init(); + * 3. 全局使用方法:InitPHP::cli_init(); + * @param array $argv * @return object */ public static function cli_init($argv) { @@ -86,7 +88,6 @@ public static function cli_init($argv) { */ public static function rpc_init() { self::isDebug(); - $ret = array(); $params = json_decode(urldecode($_POST['params']), true); if (!is_array($params) || !$params['class'] || !$params['method']) { return InitPHP::rpc_ret(405, "params is error"); @@ -152,9 +153,9 @@ public static function rpc_init() { /** * RPC 返回结果 - * @param $code 错误码 - * @param $msg 错误信息 - * @param $data 错误内容 + * @param int $code 错误码 + * @param string $msg 错误信息 + * @param string|null $data 错误内容 */ public static function rpc_ret($code, $msg, $data = null) { $ret = array(); @@ -170,9 +171,9 @@ public static function rpc_ret($code, $msg, $data = null) { * 2. 自定义文件路径数组,自动查询,找到文件返回TRUE,找不到返回false * 3. 只需要文件名,import会自动加上APP_PATH * 全局使用方法:InitPHP::import($filename, $pathArr); - * @param $filename 文件名称 - * @param $pathArr 文件路径 - * @return file + * @param string $filename_old 文件名称 + * @param array $pathArr 文件路径 + * @return string file */ public static function import($filename_old, array $pathArr = array()) { $filename = InitPHP::getAppPath($filename_old); @@ -204,13 +205,14 @@ public static function import($filename_old, array $pathArr = array()) { * 2. 可强制重新实例化 * 全局使用方法:InitPHP::loadclass($classname, $force = false) * @param string $classname + * @param bool $force * @return object */ public static function loadclass($classname, $force = false) { - if (preg_match('/[^a-z0-9\-_.]/i', $classname)) InitPHP::initError('invalid classname'); + if (preg_match('/[^a-z0-9\-_.]/i', $classname)) InitPHP::initError("invalid classname:{$classname}"); if ($force == true) unset(parent::$instance['loadclass'][$classname]); if (!isset(parent::$instance['loadclass'][$classname])) { - if (!class_exists($classname)) InitPHP::initError($classname . ' is not exist!'); + if (!class_exists($classname)) InitPHP::initError( "$classname is not exist!"); $Init_class = new $classname; parent::$instance['loadclass'][$classname] = $Init_class; } @@ -224,7 +226,7 @@ public static function loadclass($classname, $force = false) { * 全局使用方法:InitPHP::hook($hookname, $data = ''); * @param string $hookname 挂钩名称 * @param string $data 传递的参数 - * @return + * @return bool */ public static function hook($hookname, $data = '') { $InitPHP_conf = InitPHP::getConfig(); @@ -241,6 +243,7 @@ public static function hook($hookname, $data = '') { self::_hook($v[0], $v[1], $data); } } + return true; } /** @@ -312,7 +315,7 @@ public static function getService($servicename, $path = '') { * 静态方式调用扩展库中的类 * 单例模式,和$this->getLibrary方法是一样的 * 全局使用方法:InitPHP::getLibrarys("curl") - * @param $className 例如调用curlInit类,则$className = curl,不需要后缀 Init + * @param string $className 例如调用curlInit类,则$className = curl,不需要后缀 Init * @return object */ public static function getLibrarys($className) { @@ -332,7 +335,7 @@ public static function getLibrarys($className) { * 静态方式调用工具库中的类 * 单例模式,和$this->getUtil方法是一样的 * 全局使用方法:InitPHP::getUtils("queue") - * @param $className 例如调用queueInit类,则$className = queue,不需要后缀 Init + * @param string $className 例如调用queueInit类,则$className = queue,不需要后缀 Init * @return object */ public static function getUtils($className) { @@ -364,12 +367,14 @@ public static function log($message, $log_type = 'DEBUG') { * 1. 如果调用成功,则返回结果 * 2. 如果业务层异常,则抛出 Exception 异常信息,需要外部捕获处理 * 3. 调用服务异常,则抛出 exceptionInit 异常信息,需要外部捕获处理 - * @param $class 类名称,例如userService,则user - * @param $method 方法名称,例如 getUse - * @param $args 参数,按照参数排序 - * @param $group 参数,分组参数 - * @param $path Service的模块名称 - * @param $timeout 最长请求时间 + * @param string $class 类名称,例如userService,则user + * @param string $method 方法名称,例如 getUse + * @param array $args 参数,按照参数排序 + * @param string $group 参数,分组参数 + * @param string $path Service的模块名称 + * @param int $timeout 最长请求时间 + * @throws Exception + * @return string */ public static function getRemoteService($class, $method, $args = array(), $group = "default", $path = "", $timeout = 5) { $InitPHP_conf = InitPHP::getConfig(); @@ -397,7 +402,7 @@ public static function getRemoteService($class, $method, $args = array(), $group } $ret = json_decode($json, true); //服务层调用失败,抛出exceptionInit异常 - if (!ret) { + if (!$ret) { throw new exceptionInit("Rpc call fail!", 405); } if ($ret["code"] == 405) { @@ -503,8 +508,7 @@ public static function url($action, $params = array(), $baseUrl = '') { * 获取时间戳 * 1. 静态时间戳函数 * 全局使用方法:InitPHP::getTime(); - * @param $msg - * @return html + * @return int */ public static function getTime() { if (self::$time > 0) return self::$time; @@ -530,6 +534,7 @@ public static function getTime() { * ) * 7. 默认为空,则全部有权限 * @param array $config + * @return bool */ public static function acl($config = array()) { $InitPHP_conf = InitPHP::getConfig(); @@ -598,7 +603,8 @@ public static function getAppPath($path = '') { * 1. 框架的错误信息输出函数,尽量不要使用在项目中 * 全局使用方法:InitPHP::initError($msg) * @param $msg - * @return html + * @param $code + * @throws exceptionInit */ public static function initError($msg, $code = 10000) { throw new exceptionInit($msg, $code); @@ -609,11 +615,11 @@ public static function initError($msg, $code = 10000) { * 1. 一般不建议采用Controller调用另外一个Controller中的方法 * 2. 该函数可以用于接口聚集,将各种接口聚集到一个接口中使用 * 全局使用方法:InitPHP::getController($controllerName, $functionName) - * @param $controllerName 控制器名称 - * @param $functionName 方法名称 - * @param $params 方法参数 - * @param $controllerPath 控制器文件夹名称,例如在控制器文件夹目录中,还有一层目录,user/则,该参数需要填写 - * @return + * @param string $controllerName 控制器名称 + * @param string $functionName 方法名称 + * @param array $params 方法参数 + * @param string $controllerPath 控制器文件夹名称,例如在控制器文件夹目录中,还有一层目录,user/则,该参数需要填写 + * @return bool */ public static function getController($controllerName, $functionName, $params = array(), $controllerPath = '') { $InitPHP_conf = InitPHP::getConfig(); @@ -634,6 +640,8 @@ public static function getController($controllerName, $functionName, $params = a } else { call_user_func_array(array($controller, $functionName), $params); } + + return true; } /**