123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- class Dever
- {
- public static $data = array();
- private static $define = array();
- public static $string = 'Dever\\String\\Helper';
- public static $date = 'Dever\\Support\\Date';
- public static $env = 'Dever\\String\\Env';
- public static $path = 'Dever\\Path';
- public static $page = 'Dever\\Paginator';
- public static function run()
- {
- $route = Dever\Route::get();
- Dever\Debug::init();
- 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(self::$data[$index])) {
- self::$data[$index] = new Dever\Import($class, $app, $path);
- }
- return self::$data[$index]->loadDevelop();
- }
- public static function db($table, $app = '', $store = 'default', $partition = false, $path = 'table')
- {
- if (!$app) {
- $app = DEVER_APP_NAME;
- }
- $index = $app . $path . $table;
- if (empty(self::$data[$index])) {
- self::$data[$index] = new Dever\Model($table, $app, $store, $partition, $path);
- }
- return self::$data[$index];
- }
- public static function config()
- {
- return Dever\Config::get(...func_get_args());
- }
- public static function apply()
- {
- return Library::get()->apply(...func_get_args());
- }
- public static function success()
- {
- return Dever\Output::success(...func_get_args());
- }
- public static function error()
- {
- return Dever\Output::error(...func_get_args());
- }
- public static function out()
- {
- return Dever\Output::out(...func_get_args());
- }
- public static function input()
- {
- return Dever\Route::input(...func_get_args());
- }
- public static function url()
- {
- return Dever\Route::url(...func_get_args());
- }
- public static function project()
- {
- return Dever\Project::load(...func_get_args());
- }
- public static function log()
- {
- return Dever\Log::add(...func_get_args());
- }
- public static function lang()
- {
- return Dever\Lang::get(...func_get_args());
- }
- public static function rule()
- {
- return Dever\String\Regular::rule(...func_get_args());
- }
- public static function session()
- {
- return Dever\Session::oper(...func_get_args());
- }
- public static function shell($value)
- {
- return Dever::check(Dever\Route::input('shell'), $value);
- }
- public static function store($store = 'default', $partition = false)
- {
- $setting = Dever\Config::get('setting')['database'][$store];
- $class = 'Dever\\Store\\' . $setting['type'];
- return $class::getInstance($store, $setting, $partition);
- }
- 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);
- 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 ($type == 2) {
- return number_format($number, $num);
- }
- if ($type == 3) {
- return round($number, $num);
- }
- return sprintf("%.".$num."f", $number);
- }
- }
|