dever.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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(self::$data[$index])) {
  43. self::$data[$index] = new Dever\Import($class, $app, $path);
  44. }
  45. return self::$data[$index]->loadDevelop();
  46. }
  47. public static function db($table, $app = '', $path = 'table')
  48. {
  49. if (!$app) {
  50. $app = DEVER_APP_NAME;
  51. }
  52. $index = $app . $path . $table;
  53. if (empty(self::$data[$index])) {
  54. self::$data[$index] = new Dever\Model($table, $app, $path);
  55. }
  56. return self::$data[$index];
  57. }
  58. public static function config()
  59. {
  60. return Dever\Config::get(...func_get_args());
  61. }
  62. public static function apply()
  63. {
  64. return Library::get()->apply(...func_get_args());
  65. }
  66. public static function success()
  67. {
  68. return Dever\Output::success(...func_get_args());
  69. }
  70. public static function error()
  71. {
  72. return Dever\Output::error(...func_get_args());
  73. }
  74. public static function out()
  75. {
  76. return Dever\Output::out(...func_get_args());
  77. }
  78. public static function input()
  79. {
  80. return Dever\Route::input(...func_get_args());
  81. }
  82. public static function url()
  83. {
  84. return Dever\Route::url(...func_get_args());
  85. }
  86. public static function project()
  87. {
  88. return Dever\Project::load(...func_get_args());
  89. }
  90. public static function log()
  91. {
  92. return Dever\Log::add(...func_get_args());
  93. }
  94. public static function lang()
  95. {
  96. return Dever\Lang::get(...func_get_args());
  97. }
  98. public static function rule()
  99. {
  100. return Dever\String\Regular::rule(...func_get_args());
  101. }
  102. public static function session()
  103. {
  104. return Dever\Session::oper(...func_get_args());
  105. }
  106. public static function string()
  107. {
  108. return Dever\String\Helper;
  109. }
  110. public static function env()
  111. {
  112. return Dever\String\Env;
  113. }
  114. public static function path()
  115. {
  116. return Dever\Path;
  117. }
  118. public static function shell($value)
  119. {
  120. return Dever::check(Dever\Route::input('shell'), $value);
  121. }
  122. public static function check($var, $find)
  123. {
  124. if (is_array($var)) {
  125. $var = implode(',', $var);
  126. }
  127. $var = ',' . $var . ',';
  128. $find = ',' . $find . ',';
  129. return strpos($var, $find) !== false;
  130. }
  131. public static function json_encode($value)
  132. {
  133. $value = json_encode($value, JSON_UNESCAPED_UNICODE + JSON_FORCE_OBJECT);
  134. return $value;
  135. }
  136. public static function json_decode($value)
  137. {
  138. return json_decode($value, true);
  139. }
  140. public static function array_order($array, $key, $sort)
  141. {
  142. $reorder = array_column($array, $key);
  143. array_multisort($reorder, $sort, $array);
  144. return $array;
  145. }
  146. public static function number($number, $num = 2, $type = 1)
  147. {
  148. if ($type == 2) {
  149. return number_format($number, $num);
  150. }
  151. if ($type == 3) {
  152. return round($number, $num);
  153. }
  154. return sprintf("%.".$num."f", $number);
  155. }
  156. }