rabin 10 months ago
parent
commit
a54ea0a246

+ 2 - 2
src/Dever/File.php

@@ -16,8 +16,8 @@ class File
         $path = dirname($file);
         if (!is_dir($path)) {
             mkdir($path, 0777, true);
-            @chmod($path, 0755);
-            @system('chmod -R 777 ' . $path);
+            @chmod($path, 0777);
+            //@system('chmod -R 777 ' . $path);
         }
         return $file;
     }

+ 2 - 2
src/Dever/Helper/Cmd.php

@@ -40,8 +40,8 @@ class Cmd
         if ($daemon) {
             $shell .= ' 1>/dev/null 2>&1 &';
         }
-        $result = exec($shell);
-        return $result;
+        exec($shell, $output, $state);
+        return array($state == 0, $output);
     }
     public static function bash($cmd)
     {

+ 16 - 0
src/Dever/Helper/Curl.php

@@ -78,6 +78,19 @@ class Curl
             }
         }
     }
+    public function setStream($callback)
+    {
+        curl_setopt($this->handle, CURLOPT_BUFFERSIZE, 16384);
+        // 检查是否断联,每10秒发送一次心跳
+        curl_setopt($this->handle,CURLOPT_TCP_KEEPALIVE,1);   // 开启
+        curl_setopt($this->handle,CURLOPT_TCP_KEEPIDLE,10);   // 空闲10秒问一次
+        curl_setopt($this->handle,CURLOPT_TCP_KEEPINTVL,10);  // 每10秒问一次
+        curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($callback) {
+            call_user_func($callback, $data);            
+            return strlen($data);
+        });
+        return $this;
+    }
     public function setRequest($type)
     {
         if ($type == 'post' || $type == 'file') {
@@ -197,6 +210,9 @@ class Curl
                 Dever::log($debug, 'curl');
             }
             Dever::debug($debug, 'curl');
+            if (isset($setting['stream'])) {
+                exit;
+            }
             return $result;
         } catch (\Exception $e) {
             curl_close($this->handle);

+ 28 - 0
src/Dever/Helper/Str.php

@@ -274,4 +274,32 @@ class Str
         }
         return $base64;
     }
+    public static function getLink($text)
+    {
+        preg_match("/(https:|https:)(\/\/[A-Za-z0-9_#?.&=\/]+)([".chr(0xb0)."-".chr(0xf7)."][".chr(0xa1)."-".chr(0xfe)."])?(\s)?/i", $text, $result);
+
+        if (isset($result[0])) {
+            return $result[0];
+        }
+        return false;
+    }
+    public static function val($show, $data)
+    {
+        if (strpos($show, '{') !== false && strpos($show, '{"') === false) {
+            $func = function ($r) use ($data) {
+                if (isset($data[$r[1]])) {
+                    return $data[$r[1]];
+                }
+                return false;
+            };
+            $show = preg_replace_callback('/{(.*?)}/', $func, $show);
+        }
+
+        $eval = '$show = "' . $show . '";';
+        @eval($eval);
+        if (is_numeric($show)) {
+            $show = (float) $show;
+        }
+        return $show;
+    }
 }

+ 2 - 2
src/Dever/Import.php

@@ -2,8 +2,8 @@
 use Dever;
 class Import
 {
-    protected $class;
-    protected $path;
+    public $class;
+    public $path;
     public function __construct($class, $app, $path)
     {
         $this->class = false;

+ 1 - 1
src/Dever/Log.php

@@ -67,7 +67,7 @@ class Log
         $state = error_log($log, 3, $file);
         if ($state && !$exists) {
             @chmod($file, 0755);
-            @system('chmod -R 777 ' . $file);
+            //@system('chmod -R 777 ' . $file);
         }
         return $state;
     }

+ 3 - 0
src/Dever/Model.php

@@ -291,6 +291,9 @@ class Model
                 $this->config['struct'][$key]['option'] = $option;
             }
             if ($value && $option) {
+                if (is_array($value) && isset($value[$key])) {
+                    $value = $value[$key];
+                }
                 if (strpos($value, ',')) {
                     $temp = explode(',', $value);
                     $result = array();

+ 2 - 0
src/Dever/Output.php

@@ -61,6 +61,8 @@ class Output
         self::callback($result);
         self::func($result);
         if (self::$format == 'json') {
+            header('Content-Type: application/json');
+            header('Content-Length: ' . strlen($result));
             print_r($result);
         } else {
             self::html($result);

+ 4 - 1
src/Dever/Route.php

@@ -33,7 +33,7 @@ class Route
         }
         return $value;
     }
-    public static function url($uri = false, $param = array())
+    public static function url($uri = false, $param = array(), $auth = false)
     {
         if ($uri == false) {
             if (DEVER_APP_HOST) {
@@ -60,6 +60,9 @@ class Route
         if (!$uri) {
             return $project['url'];
         }
+        if ($auth) {
+            $param['authorization'] = \Dever\Helper\Str::encode(\Dever\Helper\Env::header('authorization'));
+        }
         if ($route = Config::get('setting')['route']) {
             if ($search = array_search($uri, $route)) {
                 $uri = $search;