123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?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 main
- * 主头文件及全局方法
- * @author jgao
- */
- require __DIR__ . '/../globals.php';
- require __DIR__ . '/Autoloader.php';
- Autoloader::register();
- // <editor-fold defaultstate="collapsed">
- function gzip_encode($data) {
- return GZip::encode($data);
- }
- function gzip_decode($data) {
- return GZip::decode($data);
- }
- function console($obj) {
- Log::console($obj);
- }
- function debug_stack_trace() {
- if ($GLOBALS['API_TEST']) {
- $array = debug_backtrace();
- unset($array[0]);
- foreach ($array as $row) {
- $html .= $row['file'] . ':' . $row['line'] . '行,调用方法:' . $row['function'] . "<p>";
- }
- echo $html;
- }
- }
- function random($min, $max) {
- return Rand::random($min, $max);
- }
- function random_percent($percent) {
- return Rand::randomPercent($percent);
- }
- function random_prob($probs) {
- return Rand::randomProb($probs);
- }
- function dict_contains_key($dict, $property) {
- return STL::dictContainsKey($dict, $property);
- }
- function dict_remove($dict, $property) {
- STL::dictRemove($dict, $property);
- }
- function dict_insert($dict, $property, $value) {
- STL::dictInsert($dict, $property, $value);
- }
- function dict_value($dict, $property) {
- return STL::dictValue($dict, $property);
- }
- function dict_count($dict) {
- return STL::count($dict);
- }
- function dict_propertys($dict) {
- return STL::dictPropertys($dict);
- }
- function dict_values($dict) {
- return STL::dictValues($dict);
- }
- function dict_random($dict) {
- return STL::dictRandom($dict);
- }
- function dict_randoms($dict, $nums) {
- return STL::dictRandoms($dict, $nums);
- }
- function dict_to_array($dict, $mod, $propertyList = null) {
- return STL::dictToArray($dict, $mod, $propertyList);
- }
- function array_pushs(&$array, $items) {
- $array = array_merge($array, $items);
- }
- function array_get(&$array, $index) {
- return STL::arrayGet($array, $index);
- }
- function array_set(&$array, $index, $item) {
- STL::arraySet($array, $index, $item);
- }
- function array_insert(&$array, $index, $item) {
- STL::arrayInsert($array, $index, $item);
- }
- function array_remove(&$array, $item) {
- STL::arrayRemove($array, $item);
- }
- function array_remove_at(&$array, $index) {
- STL::arrayRemoveAt($array, $index);
- }
- function array_contains(&$array, $item) {
- return STL::arrayContains($array, $item);
- }
- function array_index_of(&$array, $item) {
- return STL::arrayIndexOf($array, $item);
- }
- function array_clear(&$array) {
- return STL::arrayClear($array);
- }
- function array_clone(&$array) {
- return STL::arrayClone($array);
- }
- function array_sort(&$array) {
- return STL::arraySort($array);
- }
- function array_rsort(&$array) {
- return STL::arrayRsort($array);
- }
- function array_count(&$array) {
- return STL::count($array);
- }
- function array_random(&$array) {
- return STL::arrayRandom($array);
- }
- function array_randoms(&$array, $num) {
- return STL::arrayRandoms($array, $num);
- }
- function array_uniqueness(&$array) {
- return STL::arrayUnique($array);
- }
- function str_contains($str, $sub) {
- return Strings::contains($str, $sub);
- }
- function strsplit($str, $char = ',') {
- return Strings::split($str, $char);
- }
- function strsplit_raw($str, $char = ',') {
- return Strings::splitRaw($str, $char);
- }
- function now($offset = 0) {
- return Time::now($offset);
- }
- function daytotime($day = 0) {
- if ($day == 0) {
- $day = day();
- }
- return $day * 86400 - 28800;
- }
- function millisecond() {
- list($s1, $s2) = explode(' ', microtime());
- return (float) sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
- }
- function hours($time = -1) {
- return Time::hours($time);
- }
- function days($time = -1) {
- return Time::days($time);
- }
- function weeks($time = -1) {
- return Time::weeks($time);
- }
- function datetime($time = 0) {
- return Time::date($time);
- }
- function request($url, $data) {
- return Web::request($url, $data);
- }
- function query_string() {
- return Web::getQueryString();
- }
- function query_paras() {
- return Web::getQueryParas();
- }
- // </editor-fold>
- function db() {
- $db = new MySql();
- $db->conn(CDB_HOST, CDB_PORT, CDB_USER, CDB_PASS, CDB_NAME);
- return $db;
- }
- /**
- * get dao instance,
- * @version 2019年12月23日 经过梦幻星工场2一年多的使用, 未发现特别明显的bug. 决定侧重使用. -- 王刚
- * 2017.06.23 第一版 学习自禅道的开源框架. -- 王刚
- * @staticvar type $a
- * @return \dao 注意: dao并非什么好东西,只是一些改进尝试, 稳定性, 性能, 效率尚未得到证明.-gwang 2017.06.23
- */
- function daoInst() {
- static $a = null;
- if (is_null($a)) {
- $cfg = array(
- 'persistant' => false,
- 'driver' => 'mysql',
- 'encoding' => 'UTF8',
- 'strictMode' => false,
- // 'emulatePrepare' => true,
- // 'bufferQuery' => true,
- 'prefix' => '',
- 'host' => CDB_HOST,
- 'port' => CDB_PORT,
- 'name' => CDB_NAME,
- 'user' => CDB_USER,
- 'password' => CDB_PASS);
- $a = new dao(); # 结束请求的时候自动回收,无需主动写关闭代码
- $a->connectDB(json_decode(json_encode(array('paydb' => $cfg)))); # 建立链接,传入配置文件
- }
- return $a;
- }
- function getPageUrl($tag) {
- if ($tag == "login" || $tag == "index") {
- return ROOT_URL . "home/" . $tag . ".html";
- } else {
- return ROOT_URL . "home/pages/" . $tag . "/" . $tag . ".html";
- }
- }
|