123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- class Dever
- {
- public static $data = array();
- private static $define = array();
- public static function run()
- {
- if (Dever\Config::get('setting')['debug']) {
- Dever\Debug::report();
- }
- $route = Dever\Route::get();
- Dever\Project::register();
- Dever\Output::success(self::load($route['l'], DEVER_APP_NAME, 'api'));
- }
- public static function __callStatic($name, $param = array())
- {
- if (isset(self::$define[$name])) {
- if (is_array(self::$define[$name])) {
- $class = self::$define[$name][0];
- $method = self::$define[$name][1];
- } else {
- $class = self::$define[$name];
- $method = $name;
- }
- if (is_object($class)) {
- return $class->$method(...$param);
- } else {
- return $class::$method(...$param);
- }
- }
- }
- public static function reg($method, $function)
- {
- self::$define[$method] = $function;
- }
- public static function load($class, $app = '', $path = 'lib')
- {
- if (!$app) {
- $app = DEVER_APP_NAME;
- }
- $index = $app . $path . $class;
- if (empty(Dever\Import::$instance[$index])) {
- Dever\Import::$instance[$index] = new Dever\Import($class, $app, $path);
- }
- return Dever\Import::$instance[$index]->loadDevelop();
- }
- public static function config($key, $app = '', $path = 'config')
- {
- return Dever\Config::get($key, $app, $path);
- }
- public static function apply($file, $app, $path = 'lib')
- {
- return Library::get()->apply($file, $app, $path);
- }
- public static function success($data, $uuid = false, $code = 0)
- {
- return Dever\Output::success($data, $uuid, $code);
- }
- public static function error($msg, $param = array(), $code = 1)
- {
- return Dever\Output::error($msg, $param, $code);
- }
- public static function out($result)
- {
- return Dever\Output::out($result);
- }
- public static function input($key = false, $lang = '', $condition = '', $value = '')
- {
- return Dever\Route::input($key, $lang, $condition, $value);
- }
- public static function url($uri = false, $param = array())
- {
- return Dever\Route::url($uri, $param);
- }
- public static function project($app)
- {
- return Dever\Project::load($app);
- }
- public static function log($msg, $type = 1)
- {
- return Dever\Log::add($msg, $type);
- }
- public static function lang($key = 'host', $param = array())
- {
- return Dever\Lang::get($key, $param);
- }
- public static function rule($method, $fix = '/', $rule = '')
- {
- return Dever\String\Regular::rule($method, $fix, $rule);
- }
- public static function session($key, $value = false, $timeout = 3600, $type = 'cookie', $encode = true)
- {
- return Dever\Session::oper($key, $value, $timeout, $type, $encode);
- }
- public static function string()
- {
- return Dever\String\Helper;
- }
- public static function env()
- {
- return Dever\String\Env;
- }
- public static function path()
- {
- return Dever\Path;
- }
- public static function check($var, $find)
- {
- if (is_array($var)) {
- $var = implode(',', $var);
- }
- $var = ',' . $var . ',';
- $find = ',' . $find . ',';
- return strpos($var, $find) !== false;
- }
- public static function json_encode($value)
- {
- $value = json_encode($value, JSON_UNESCAPED_UNICODE + JSON_FORCE_OBJECT);
- return $value;
- }
- public static function json_decode($value)
- {
- return json_decode($value, true);
- }
- public static function array_order($array, $key, $sort)
- {
- $reorder = array_column($array, $key);
- array_multisort($reorder, $sort, $array);
- return $array;
- }
- public static function number($number, $num = 2, $type = 1)
- {
- if (is_array($number)) {
- foreach ($number[0] as $k => $v) {
- $number[1][$v] = self::number($number[1][$v], $num, $type);
- }
- return $number[1];
- }
- if ($type == 2) {
- return number_format($number, $num);
- }
- if ($type == 3) {
- return round($number, $num);
- }
- return sprintf("%.".$num."f", $number);
- }
- }
|