main.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. * Description of main
  9. * 主头文件及全局方法
  10. * @author jgao
  11. */
  12. require __DIR__ . '/../globals.php';
  13. require __DIR__ . '/Autoloader.php';
  14. Autoloader::register();
  15. // <editor-fold defaultstate="collapsed">
  16. function gzip_encode($data) {
  17. return GZip::encode($data);
  18. }
  19. function gzip_decode($data) {
  20. return GZip::decode($data);
  21. }
  22. function console($obj) {
  23. Log::console($obj);
  24. }
  25. function debug_stack_trace() {
  26. if ($GLOBALS['API_TEST']) {
  27. $array = debug_backtrace();
  28. unset($array[0]);
  29. foreach ($array as $row) {
  30. $html .= $row['file'] . ':' . $row['line'] . '行,调用方法:' . $row['function'] . "<p>";
  31. }
  32. echo $html;
  33. }
  34. }
  35. function random($min, $max) {
  36. return Rand::random($min, $max);
  37. }
  38. function random_percent($percent) {
  39. return Rand::randomPercent($percent);
  40. }
  41. function random_prob($probs) {
  42. return Rand::randomProb($probs);
  43. }
  44. function dict_contains_key($dict, $property) {
  45. return STL::dictContainsKey($dict, $property);
  46. }
  47. function dict_remove($dict, $property) {
  48. STL::dictRemove($dict, $property);
  49. }
  50. function dict_insert($dict, $property, $value) {
  51. STL::dictInsert($dict, $property, $value);
  52. }
  53. function dict_value($dict, $property) {
  54. return STL::dictValue($dict, $property);
  55. }
  56. function dict_count($dict) {
  57. return STL::count($dict);
  58. }
  59. function dict_propertys($dict) {
  60. return STL::dictPropertys($dict);
  61. }
  62. function dict_values($dict) {
  63. return STL::dictValues($dict);
  64. }
  65. function dict_random($dict) {
  66. return STL::dictRandom($dict);
  67. }
  68. function dict_randoms($dict, $nums) {
  69. return STL::dictRandoms($dict, $nums);
  70. }
  71. function dict_to_array($dict, $mod, $propertyList = null) {
  72. return STL::dictToArray($dict, $mod, $propertyList);
  73. }
  74. function array_pushs(&$array, $items) {
  75. $array = array_merge($array, $items);
  76. }
  77. function array_get(&$array, $index) {
  78. return STL::arrayGet($array, $index);
  79. }
  80. function array_set(&$array, $index, $item) {
  81. STL::arraySet($array, $index, $item);
  82. }
  83. function array_insert(&$array, $index, $item) {
  84. STL::arrayInsert($array, $index, $item);
  85. }
  86. function array_remove(&$array, $item) {
  87. STL::arrayRemove($array, $item);
  88. }
  89. function array_remove_at(&$array, $index) {
  90. STL::arrayRemoveAt($array, $index);
  91. }
  92. function array_contains(&$array, $item) {
  93. return STL::arrayContains($array, $item);
  94. }
  95. function array_index_of(&$array, $item) {
  96. return STL::arrayIndexOf($array, $item);
  97. }
  98. function array_clear(&$array) {
  99. return STL::arrayClear($array);
  100. }
  101. function array_clone(&$array) {
  102. return STL::arrayClone($array);
  103. }
  104. function array_sort(&$array) {
  105. return STL::arraySort($array);
  106. }
  107. function array_rsort(&$array) {
  108. return STL::arrayRsort($array);
  109. }
  110. function array_count(&$array) {
  111. return STL::count($array);
  112. }
  113. function array_random(&$array) {
  114. return STL::arrayRandom($array);
  115. }
  116. function array_randoms(&$array, $num) {
  117. return STL::arrayRandoms($array, $num);
  118. }
  119. function array_uniqueness(&$array) {
  120. return STL::arrayUnique($array);
  121. }
  122. function str_contains($str, $sub) {
  123. return Strings::contains($str, $sub);
  124. }
  125. function strsplit($str, $char = ',') {
  126. return Strings::split($str, $char);
  127. }
  128. function strsplit_raw($str, $char = ',') {
  129. return Strings::splitRaw($str, $char);
  130. }
  131. function now($offset = 0) {
  132. return Time::now($offset);
  133. }
  134. function daytotime($day = 0) {
  135. if ($day == 0) {
  136. $day = day();
  137. }
  138. return $day * 86400 - 28800;
  139. }
  140. function millisecond() {
  141. list($s1, $s2) = explode(' ', microtime());
  142. return (float) sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
  143. }
  144. function hours($time = -1) {
  145. return Time::hours($time);
  146. }
  147. function days($time = -1) {
  148. return Time::days($time);
  149. }
  150. function weeks($time = -1) {
  151. return Time::weeks($time);
  152. }
  153. function datetime($time = 0) {
  154. return Time::date($time);
  155. }
  156. function request($url, $data) {
  157. return Web::request($url, $data);
  158. }
  159. function query_string() {
  160. return Web::getQueryString();
  161. }
  162. function query_paras() {
  163. return Web::getQueryParas();
  164. }
  165. // </editor-fold>
  166. function db() {
  167. $db = new MySql();
  168. $db->conn(CDB_HOST, CDB_PORT, CDB_USER, CDB_PASS, CDB_NAME);
  169. return $db;
  170. }
  171. /**
  172. * get dao instance,
  173. * @version 2019年12月23日 经过梦幻星工场2一年多的使用, 未发现特别明显的bug. 决定侧重使用. -- 王刚
  174. * 2017.06.23 第一版 学习自禅道的开源框架. -- 王刚
  175. * @staticvar type $a
  176. * @return \dao 注意: dao并非什么好东西,只是一些改进尝试, 稳定性, 性能, 效率尚未得到证明.-gwang 2017.06.23
  177. */
  178. function daoInst() {
  179. static $a = null;
  180. if (is_null($a)) {
  181. $cfg = array(
  182. 'persistant' => false,
  183. 'driver' => 'mysql',
  184. 'encoding' => 'UTF8',
  185. 'strictMode' => false,
  186. // 'emulatePrepare' => true,
  187. // 'bufferQuery' => true,
  188. 'prefix' => '',
  189. 'host' => CDB_HOST,
  190. 'port' => CDB_PORT,
  191. 'name' => CDB_NAME,
  192. 'user' => CDB_USER,
  193. 'password' => CDB_PASS);
  194. $a = new dao(); # 结束请求的时候自动回收,无需主动写关闭代码
  195. $a->connectDB(json_decode(json_encode(array('paydb' => $cfg)))); # 建立链接,传入配置文件
  196. }
  197. return $a;
  198. }
  199. function getPageUrl($tag) {
  200. if ($tag == "login" || $tag == "index") {
  201. return ROOT_URL . "home/" . $tag . ".html";
  202. } else {
  203. return ROOT_URL . "home/pages/" . $tag . "/" . $tag . ".html";
  204. }
  205. }