rabin 8 months ago
parent
commit
2393ee78c3

+ 2 - 1
boot.php

@@ -46,6 +46,7 @@ class Dever
     }
     public static function call($class, $param = array(), $path = '')
     {
+        if (!is_array($param)) $param = array($param);
         if (strpos($class, '?')) {
             list($class, $temp) = explode('?', $class);
             parse_str($temp, $temp);
@@ -230,7 +231,7 @@ class Dever
     public static function json_encode($value)
     {
         //$value = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK | JSON_PRESERVE_ZERO_FRACTION);
-        $value = json_encode($value, JSON_UNESCAPED_UNICODE);
+        $value = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
         /*
         if (strpos($value, '<')) {
             $value = Dever\Helper\Secure::xss($value);

+ 26 - 0
src/Dever/Helper/Arr.php

@@ -15,4 +15,30 @@ class Arr
         }
         return $result;
     }
+
+    public static function queryString($arr, $sort = 'ksort', $kvlink = '=', $link = '&', $kencode = '', $vencode = '')
+    {
+        if ($sort) {
+            if is_array($sort) {
+                list($method, $param) = $sort;
+                $method($arr, $param);
+            } else {
+                $sort($arr);
+            }
+        }
+        $result = array();
+        foreach ($arr as $k => $v) {
+            if (null === $v) {
+                continue;
+            }
+            $str = rawurlencode($k);
+            if ('' !== $v && null !== $v) {
+                $str .= '=' . rawurlencode($v);
+            } else {
+                $str .= '=';
+            }
+            $result[] = $str;
+        }
+        return implode($link, $result);
+    }
 }

+ 3 - 0
src/Dever/Helper/Cmd.php

@@ -15,6 +15,9 @@ class Cmd
             $app = $app ? $app : DEVER_APP_NAME;
         }
         $app = Dever::project($app);
+        if (isset($app['setup'])) {
+            $app['path'] = $app['setup'];
+        }
         if (strpos($app['path'], 'http') !== false) {
             return self::shell('curl "' . $app['path'] . $api . '"', $daemon);
         } else {

+ 7 - 10
src/Dever/Helper/Curl.php

@@ -133,9 +133,9 @@ class Curl
     {
         if (is_array($param)) {
             if (isset($param['item_desc'])) {
-                $param = json_encode($param, JSON_UNESCAPED_UNICODE);
+                $param = Dever::json_encode($param);
             } else {
-                $param = json_encode($param);
+                $param = Dever::json_encode($param);
             }
         }
         $header['Content-Type'] = 'application/json';
@@ -199,21 +199,18 @@ class Curl
                 $result = curl_getinfo($this->handle);
             }
             curl_close($this->handle);
-            $data = $result;
-            if (!Dever::shell('all') && is_array($data)) {
-                $data = count($data) . ' records';
-            }
             $debug['url'] = $this->url;
-            $debug['body'] = $this->param;
-            $debug['header'] = $this->header;
-            $debug['result'] = $data;
+            $debug['request_body'] = $this->param;
+            $debug['request_header'] = $this->header;
+            $debug['response_body'] = $result;
+            $debug['response_header'] = $this->result_header;
             if ($this->log) {
                 Dever::log($debug, 'curl');
+                Dever::debug($debug, 'curl');
             }
             if (Dever::input('test') == 1) {
                 echo Dever::json_encode($debug);die;
             }
-            Dever::debug($debug, 'curl');
             if (isset($setting['stream'])) {
                 exit;
             }

+ 1 - 1
src/Dever/Helper/Secure.php

@@ -9,7 +9,7 @@ class Secure
         $data = Dever::json_encode(array($uid, time(), $extend));
         return self::encode($data);
     }
-    public static function checkLogin($signature, $time = 604800)
+    public static function checkLogin($signature, $time = 31536000)
     {
         self::repeat($signature, $time);
         $auth = Dever::json_decode(self::decode($signature));

+ 1 - 1
src/Dever/Helper/Str.php

@@ -295,7 +295,7 @@ class Str
             $show = preg_replace_callback('/{(.*?)}/', $func, $show);
         }
 
-        if (strstr($show, '"')) {
+        if (strstr($show, '"') || strstr($show, "'")) {
             $eval = '$show =  ' . $show . ';';
         } else {
             $eval = '$show = "' . $show . '";';

+ 3 - 0
src/Dever/Import.php

@@ -54,6 +54,9 @@ class Import
     }
     private function loadDevelopCommit($method, $param)
     {
+        if (method_exists($this->class, $method . '_cmd') && DEVER_PROTO != 'cmd') {
+            Dever::error('route error');
+        }
         if (method_exists($this->class, $method . '_commit') && Dever::$commit) {
             $db = Dever::store();
             try {

+ 1 - 1
src/Dever/Log.php

@@ -114,7 +114,7 @@ class Log
     public static function filter($string)
     {
         if (is_array($string)) {
-            $string = json_encode($string);
+            $string = Dever::json_encode($string);
         }
         return $string;
     }

+ 9 - 4
src/Dever/Route.php

@@ -18,7 +18,7 @@ class Route
             if (!$lang) {
                 $lang = $key;
             }
-            if (!$value) {
+            if (!$value && $value !== 0) {
                 Output::error($lang . '不能为空');
             }
             $state = true;
@@ -33,7 +33,7 @@ class Route
         }
         return $value;
     }
-    public static function url($uri = false, $param = array(), $auth = false)
+    public static function url($uri = false, $param = array(), $auth = false, $rewrite = '')
     {
         if ($uri == false) {
             if (DEVER_APP_HOST) {
@@ -83,11 +83,16 @@ class Route
                         $i++;
                         return $data[$i];
                     }, $key);
+                } else {
+                    $uri .= '&' . http_build_query($param);
                 }
             }
         } elseif ($param) {
             $uri .= '&' . http_build_query($param);
         }
+        if ($rewrite) {
+            return str_replace($rewrite, '', $project['url']) . $uri;
+        }
         return $project['url'] . self::$type . $uri;
     }
     public static function host()
@@ -121,7 +126,7 @@ class Route
             if (isset($argv[1]) && $argv[1]) {
                 self::$data = \Dever::json_decode($argv[1]);
             }
-            define('DEVER_PROTO', 'command');
+            define('DEVER_PROTO', 'cmd');
             define('DEVER_APP_HOST', '');
             return true;
         }
@@ -189,7 +194,7 @@ class Route
                 } else {
                     if ($data[$k] == 'undefined') {
                         $data[$k] = '';
-                    } else {
+                    } elseif (strstr($v, '<') && strstr($v, '>')) {
                         $data[$k] = htmlspecialchars($v);
                     }
                 }

+ 18 - 6
src/Dever/Sql.php

@@ -154,7 +154,8 @@ class Sql
         if (isset($set['join'])) {
             $temp = explode('_', $table);
             $prefix = $temp[0] . '_'  . $temp[1] . '_';
-            $table .= ' AS ' . $temp[2];
+            $temp = implode('_', array_slice($temp, 2));
+            $table .= ' AS ' . $temp;
             foreach ($set['join'] as $k => $v) {
                 $table .= ' ' . $v['type'] . ' ' . $prefix . $v['table'] . ' AS ' . $v['table'] . ' ON ' . $v['on'];
             }
@@ -206,8 +207,7 @@ class Sql
                                 self::field($first_link, $bind, $i, $k1, '=', $v1, $field, $type);
                             }
                         }
-                        $first_link = ltrim($first_link, ' and ');
-                        $second .= ' ' . $k . ' (' . $first_link . $second_link . ')';
+                        $second .= ' ' . $k . ' (' . self::replace($first_link) . $second_link . ')';
                     } else {
                         if (is_array($v)) {
                             self::field($second, $bind, $i, $k, $v[0], $v[1], $field, $type);
@@ -216,7 +216,7 @@ class Sql
                         }
                     }
                 }
-                return ' WHERE ' . ltrim($first . $second, ' and ');
+                return ' WHERE ' . self::replace($first . $second);
             } elseif (is_numeric($param)) {
                 if ($type == 'Influxdb') {
                     return ' WHERE "id" = \'' . $param . '\'';
@@ -237,7 +237,12 @@ class Sql
             $type = $b;
             $b = array();
         }
-        if ($f && empty($f[$k]) && strpos('id,cdate', $k) === false) {
+        $g = '';
+        if (strstr($k, '.')) {
+            $g = explode('.', $k);
+            $k = $g[1];
+            $g = $g[0] . '.';
+        } elseif ($f && empty($f[$k]) && strpos('id,cdate', $k) === false) {
             return;
         }
         $s .= ' and ';
@@ -255,7 +260,7 @@ class Sql
                 $e = '=';
             }
         }
-        $k = $x.$k.$x;
+        $k = $g.$x.$k.$x;
         if (strpos($e,'in') !== false) {
             if (!is_array($v)) {
                 $v = explode(',', $v);
@@ -340,4 +345,11 @@ class Sql
     {
         return 'round((st_distance(point(lng, lat), point('.$lng.', '.$lat.'))*111195)/1000, 2) as distance';
     }
+    private static function replace($string)
+    {
+        if (strpos($string, ' and ') === 0) {
+            $string = substr($string, 5);
+        }
+        return $string;
+    }
 }