|
@@ -1,11 +1,33 @@
|
|
|
<?php
|
|
|
header('Content-Type: text/html; charset=utf-8');date_default_timezone_set("PRC");define('DEVER_TIME', $_SERVER['REQUEST_TIME']);define('DEVER_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
|
|
|
-Dever::run();
|
|
|
+if (defined('DEVER_SERVER')) {
|
|
|
+ Dever::server();
|
|
|
+} else {
|
|
|
+ Dever::run();
|
|
|
+}
|
|
|
class Dever
|
|
|
{
|
|
|
public static $data = array();
|
|
|
- public static $app = array();
|
|
|
public static $commit = true;
|
|
|
+ public static function server()
|
|
|
+ {
|
|
|
+ spl_autoload_register(array('Dever', 'autoload'));
|
|
|
+ $http_worker = new \Workerman\Worker("http://0.0.0.0:8085");
|
|
|
+
|
|
|
+
|
|
|
+ $http_worker->count = 4;
|
|
|
+
|
|
|
+
|
|
|
+ $http_worker->onMessage = function(\Workerman\Connection\TcpConnection $connection, $data)
|
|
|
+ {
|
|
|
+ $route = Dever\Route::get();
|
|
|
+ print_r($route);
|
|
|
+
|
|
|
+ $connection->send('hello world');
|
|
|
+ };
|
|
|
+
|
|
|
+ \Workerman\Worker::runAll();
|
|
|
+ }
|
|
|
public static function run()
|
|
|
{
|
|
|
spl_autoload_register(array('Dever', 'autoload'));
|
|
@@ -25,9 +47,11 @@ class Dever
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- self::$app[] = DEVER_APP_NAME;
|
|
|
if ($route['l'] && strpos($route['l'], '.')) {
|
|
|
list($class, $method) = explode('.', $route['l']);
|
|
|
+ if (strstr($class, 'manage/') && !strstr($class, 'api')) {
|
|
|
+ Dever\Output::error('route error');
|
|
|
+ }
|
|
|
$result = Dever\Output::success(self::load($class, DEVER_APP_NAME, 'api')->loadDevelop($method, Dever\Route::input(), true));
|
|
|
} else {
|
|
|
$result = Dever\Output::success('ok');
|
|
@@ -38,7 +62,7 @@ class Dever
|
|
|
}
|
|
|
public static function autoload($class)
|
|
|
{
|
|
|
- if (strpos($class, 'Dever') === 0) {
|
|
|
+ if (strpos($class, 'Dever') === 0 || strpos($class, 'Workerman') === 0) {
|
|
|
include DEVER_PATH . 'src/' . str_replace('\\', '/', $class) . '.php';
|
|
|
} else {
|
|
|
Dever\Library::autoload($class);
|
|
@@ -68,12 +92,7 @@ class Dever
|
|
|
public static function load($class, $app = '', $path = 'lib')
|
|
|
{
|
|
|
if (strpos($class, '/') && !$app) {
|
|
|
- list($app, $class) = explode('/', $class);
|
|
|
- }
|
|
|
- if ($app) {
|
|
|
- array_unshift(self::$app, $app);
|
|
|
- } else {
|
|
|
- $app = self::$app[0];
|
|
|
+ list($app, $class) = explode('/', $class, 2);
|
|
|
}
|
|
|
$index = $app . $path . $class;
|
|
|
if (empty(self::$data[$index])) {
|
|
@@ -86,22 +105,31 @@ class Dever
|
|
|
if (strpos($table, '/') && !$app) {
|
|
|
list($app, $table) = explode('/', $table);
|
|
|
}
|
|
|
- if ($app) {
|
|
|
- array_unshift(self::$app, $app);
|
|
|
- } else {
|
|
|
- $app = self::$app[0];
|
|
|
- }
|
|
|
$index = $app . $path . $table;
|
|
|
if (empty(self::$data[$index]) || !$cache) {
|
|
|
self::$data[$index] = new Dever\Model($table, $app, $store, $partition, $path);
|
|
|
}
|
|
|
return self::$data[$index];
|
|
|
}
|
|
|
- public static function reset()
|
|
|
+ public static function option($table, $type = '', $where = [])
|
|
|
+ {
|
|
|
+ $data = Dever::db($table)->select($where);
|
|
|
+ if ($type) {
|
|
|
+ if (is_bool($type)) {
|
|
|
+ $type = '不选择';
|
|
|
+ }
|
|
|
+ $default = array(0 => array('id' => -1, 'name' => $type));
|
|
|
+ $data = array_merge($default, $data);
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ public static function field($table, $id, $default = '无', $key = 'name')
|
|
|
{
|
|
|
- if (count(self::$app) > 1) {
|
|
|
- array_shift(self::$app);
|
|
|
+ if ($id && $id > 0) {
|
|
|
+ $info = Dever::db($table)->find($id);
|
|
|
+ return $info[$key];
|
|
|
}
|
|
|
+ return $default;
|
|
|
}
|
|
|
public static function config()
|
|
|
{
|
|
@@ -256,9 +284,9 @@ class Dever
|
|
|
return number_format($number, $num);
|
|
|
}
|
|
|
if ($type == 3) {
|
|
|
- return round($number, $num);
|
|
|
+ return sprintf("%.".$num."f", $number);
|
|
|
}
|
|
|
- return sprintf("%.".$num."f", $number);
|
|
|
+ return round($number + 0.000001, $num);
|
|
|
}
|
|
|
public static function uuid()
|
|
|
{
|