ctms/vendor/fmsoft/vars.php
2025-04-10 23:19:13 +08:00

113 lines
3.4 KiB
PHP
Executable File

<?php
/**
* @Author: fm453
* @Date: 2019-04-29 16:21:37
* @Last Modified by: fm453
* @Last Modified time: 2019-07-29 14:40:43
*/
defined('HI_FM') or exit("Access Denied");
/**
* 储存一些常用变量,方便系统全局调用
* @author fm453 (393213759)
* __CLASS__ 取类名
* __FUNCTION__ 当前函数名
* __METHOD__ 当前方法名
* get_class(class name);//取得当前语句所在类的类名
* get_class_methods(class name);//取得class name 类的所有的方法名,并且组成一个数组
* get_class_vars(class name);//取得class name 类的所有的变量名,并组成一个数组
*/
/**
* $_GPC 全局请求变量
* $_HI 归集整理应用于YII框架内的变量集
* $_FM 归集整理可输出到客户侧的变量集
**/
global $_GPC;
global $_HI;
global $_FM;
if((defined('DEBUG') && DEBUG == true) || (defined('YII_DEBUG') && YII_DEBUG == true)){
defined('FM_DEBUG') or define('FM_DEBUG',true);
}
//PHP stdClass Object转array
if(!function_exists('fm_object2array')){
function fm_object2array($array) {
if(is_object($array)) {
$array = (array)$array;
}
if(is_array($array)) {
foreach($array as $key=> &$value) {
if(is_object($value)) {
$value = (array)$value;
}
if(is_array($value)){
foreach($value as $k => &$v){
$value[$k] = fm_object2array($v);
}
}
$array[$key] = $value;
}
}
return $array;
}
}
//在YII内启用时
if(isset(Yii::$app)){
$_HI['appName'] = Yii::$app->id;
$_HI['post'] = Yii::$app->request->post(); //YII应用内的真实或模拟POST数据
$_HI['get'] = Yii::$app->request->get(); //YII应用内的真实或模拟GET数据
$params = Yii::$app->params;
if(isset(Yii::$app->controller)){
$_HI['controller'] = Yii::$app->controller->id; //当前控制器
}
if(isset(Yii::$app->requestedAction)){
$_HI['action'] = Yii::$app->requestedAction->id; //当前动作
$_HI['method'] = Yii::$app->requestedAction->actionMethod; //当前方法
}
//$_FM['yii']['route'] = Yii::$app->requestedRoute; //当前路径(controller/action)
if(isset(Yii::$app->user->identity)){
$_FM['user']['name'] = Yii::$app->user->identity->username;
$_FM['user']['uid'] = Yii::$app->user->identity->id;
}
}else{
$_HI['post'] = $_POST;
$_HI['get'] = $_GET;
}
$_FM['post'] = [];
foreach($_HI['post'] as $k => $v){
if(is_string($v)){
$v = json_decode($v);
}
$_FM['post'][$k] = fm_object2array($v);
}
$_FM['get'] = $_HI['get'];
$_FM['siteRoot'] = $_SERVER['HTTP_HOST'];
$_FM['siteUrl'] = $_SERVER['SERVER_NAME'] .$_SERVER['REQUEST_URI'];
$_FM['urlScript'] = $_SERVER['QUERY_STRING'];
$_FM['platid'] = isset($_GET['platid']) ? intval($_GET['platid']) : 0;
if(isset($_FM['apiCert']['platid'])){
$_FM['platid'] = $_FM['apiCert']['platid'];
}
$_FM['uniacid'] = isset($_GET['uniacid']) ? intval($_GET['uniacid']) : 0;
if(isset($_FM['apiCert']['uniacid'])){
$_FM['uniacid'] = $_FM['apiCert']['uniacid'];
}
$_FM['shopid'] = isset($_GET['shopid']) ? intval($_GET['shopid']) : 0;
if(isset($_FM['apiCert']['shopid'])){
$_FM['shopid'] = $_FM['apiCert']['shopid'];
}
$_FM['timestamp'] = TIMESTAMP;
$_FM['datetitle'] = date('Y-m-d H:i:s',TIMESTAMP); //转换为可视日期
return $_FM;