123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of Com
- *
- * @author jgao
- */
- class Comm {
- //put your code here
-
- /**
- * 对象克隆
- * @param type $obj
- */
- static function cloneObject($obj, $type=null){
- if($type != null){
- $clone = new $type();
- }else{
- $clone = new stdClass();
- }
- foreach ($obj as $key => $value) {
- $clone->$key = $value;
- }
- return $clone;
- }
-
- /**
- * 对象装箱
- * @param type $surObj 原始obj
- * @param type $desObj 具体obj
- */
- static function loadObject($surObj, &$desObj) {
- if($surObj==null||$desObj==null) return;
- foreach ($desObj as $key => $value) {
- if (property_exists($surObj, $key)) {
- $desObj->$key = $surObj->$key;
- }
- }
- }
-
- /**
- * 对象装箱
- * @param type $obj
- * @param type $type
- * @return type
- */
- static function loadClass($obj, $type){
- $newObj = new $type();
- self::loadObject($obj, $newObj);
- return $obj;
- }
-
- /**
- * 数组装箱
- * @param type $obj
- * @param type $type
- * @return type
- */
- static function loadArray($obj, $type){
- $array = array();
- foreach($obj as $item){
- $array[] = self::loadClass($item, $type);
- }
- return $array;
- }
-
- /**
- * 字典装箱
- * @param type $obj
- * @param type $type
- * @return \stdClass
- */
- static function loadDict($obj, $type){
- $dict = new stdClass();
- foreach($obj as $key=>$val){
- $dict->$key = self::loadClass($val, $type);
- }
- return $dict;
- }
-
- /**
- * 方法调用
- * @param type $func
- * @param type $paras
- * @param type $class
- */
- static function callFunction($func, $paras, $class=""){
- if($class == "" || $class == null){
- call_user_func_array($func, $paras);
- }else{
- call_user_func_array(array($class, $func), $paras);
- }
- }
- /**
- * 浮点数转整形
- * @param type $value
- * @return type
- */
- static function floatToInt($value){
- return round($value - 0.4999);
- }
- /**
- * 浮点数转上整形
- * @param type $value
- * @return type
- */
- static function floatToCeil($value){
- return round($value + 0.4999);
- }
- /**
- * 解析异常描述信息
- * @param type $e
- * @return type
- */
- static function getExceptMsg($e) {
- return 'Msg:'.$e->getMessage().' Code:'.$e->getCode().' File:'.$e->getFile().' Line:'.$e->getLine();
- }
-
- /**
- * 提取url参数
- * @param type $querryStr
- * @return type
- */
- static function getQuerryParas($querryStr) {
- $arr = explode("&", $querryStr);
- $querryParas = array();
- foreach ($arr as $value) {
- $paras = explode("=", $value);
- $querryParas[$paras[0]] = $paras[1];
- }
- return $querryParas;
- }
- /**
- * 获取客户端ip地址及端口
- * @return type
- */
- static function getClientEP(){
- return $_SERVER['REMOTE_ADDR'].":".$_SERVER['REMOTE_PORT'];
- }
- }
|