dever.php 4.5 KB

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