dever.php 4.2 KB

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