dever_old.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. class Dever
  3. {
  4. public static $data = array();
  5. private static $define = array();
  6. public static function run()
  7. {
  8. if (Dever\Config::get('setting')['debug']) {
  9. Dever\Debug::report();
  10. }
  11. $route = Dever\Route::get();
  12. Dever\Project::register();
  13. Dever\Output::success(self::load($route['l'], DEVER_APP_NAME, 'api'));
  14. }
  15. public static function __callStatic($name, $param = array())
  16. {
  17. if (isset(self::$define[$name])) {
  18. if (is_array(self::$define[$name])) {
  19. $class = self::$define[$name][0];
  20. $method = self::$define[$name][1];
  21. } else {
  22. $class = self::$define[$name];
  23. $method = $name;
  24. }
  25. if (is_object($class)) {
  26. return $class->$method(...$param);
  27. } else {
  28. return $class::$method(...$param);
  29. }
  30. }
  31. }
  32. public static function reg($method, $function)
  33. {
  34. self::$define[$method] = $function;
  35. }
  36. public static function load($class, $app = '', $path = 'lib')
  37. {
  38. if (!$app) {
  39. $app = DEVER_APP_NAME;
  40. }
  41. $index = $app . $path . $class;
  42. if (empty(Dever\Import::$instance[$index])) {
  43. Dever\Import::$instance[$index] = new Dever\Import($class, $app, $path);
  44. }
  45. return Dever\Import::$instance[$index]->loadDevelop();
  46. }
  47. public static function config($key, $app = '', $path = 'config')
  48. {
  49. return Dever\Config::get($key, $app, $path);
  50. }
  51. public static function apply($file, $app, $path = 'lib')
  52. {
  53. return Library::get()->apply($file, $app, $path);
  54. }
  55. public static function success($data, $uuid = false, $code = 0)
  56. {
  57. return Dever\Output::success($data, $uuid, $code);
  58. }
  59. public static function error($msg, $param = array(), $code = 1)
  60. {
  61. return Dever\Output::error($msg, $param, $code);
  62. }
  63. public static function out($result)
  64. {
  65. return Dever\Output::out($result);
  66. }
  67. public static function input($key = false, $lang = '', $condition = '', $value = '')
  68. {
  69. return Dever\Route::input($key, $lang, $condition, $value);
  70. }
  71. public static function url($uri = false, $param = array())
  72. {
  73. return Dever\Route::url($uri, $param);
  74. }
  75. public static function project($app)
  76. {
  77. return Dever\Project::load($app);
  78. }
  79. public static function log($msg, $type = 1)
  80. {
  81. return Dever\Log::add($msg, $type);
  82. }
  83. public static function lang($key = 'host', $param = array())
  84. {
  85. return Dever\Lang::get($key, $param);
  86. }
  87. public static function rule($method, $fix = '/', $rule = '')
  88. {
  89. return Dever\String\Regular::rule($method, $fix, $rule);
  90. }
  91. public static function session($key, $value = false, $timeout = 3600, $type = 'cookie', $encode = true)
  92. {
  93. return Dever\Session::oper($key, $value, $timeout, $type, $encode);
  94. }
  95. public static function string()
  96. {
  97. return Dever\String\Helper;
  98. }
  99. public static function env()
  100. {
  101. return Dever\String\Env;
  102. }
  103. public static function path()
  104. {
  105. return Dever\Path;
  106. }
  107. public static function check($var, $find)
  108. {
  109. if (is_array($var)) {
  110. $var = implode(',', $var);
  111. }
  112. $var = ',' . $var . ',';
  113. $find = ',' . $find . ',';
  114. return strpos($var, $find) !== false;
  115. }
  116. public static function json_encode($value)
  117. {
  118. $value = json_encode($value, JSON_UNESCAPED_UNICODE + JSON_FORCE_OBJECT);
  119. return $value;
  120. }
  121. public static function json_decode($value)
  122. {
  123. return json_decode($value, true);
  124. }
  125. public static function array_order($array, $key, $sort)
  126. {
  127. $reorder = array_column($array, $key);
  128. array_multisort($reorder, $sort, $array);
  129. return $array;
  130. }
  131. public static function number($number, $num = 2, $type = 1)
  132. {
  133. if (is_array($number)) {
  134. foreach ($number[0] as $k => $v) {
  135. $number[1][$v] = self::number($number[1][$v], $num, $type);
  136. }
  137. return $number[1];
  138. }
  139. if ($type == 2) {
  140. return number_format($number, $num);
  141. }
  142. if ($type == 3) {
  143. return round($number, $num);
  144. }
  145. return sprintf("%.".$num."f", $number);
  146. }
  147. }