瀏覽代碼

Fixed: bugs

Zhu Jinhui 6 年之前
父節點
當前提交
b35b73c9b2
共有 2 個文件被更改,包括 12 次插入34 次删除
  1. 11 33
      src/Config/Arrays.php
  2. 1 1
      src/Qii.php

+ 11 - 33
src/Config/Arrays.php

@@ -136,39 +136,7 @@ class Arrays
 	 */
 	public function setPrivate($key, $value)
 	{
-		preg_match_all("/(.*?)\[(.*?)\]/", $key, $match);
-		$name = '';
-		if (isset($match[1]) && isset($match[1][0])) {
-			$name = $match[1][0];
-		}
-		$keys = $match[2];
-		if ($name == '') {
-			$name = $key;
-		}
-		if (empty($keys)) {
-			$this->_private[$key] = $value;
-			return $this->_private;
-		}
-		$private = array();
-		$private = array_merge($private, $keys);
-		$privates = null;
-		if (is_array($value) || is_object($value)) {
-			$array = str_replace('[\'\']', '[]', '$privates[\'' . join("']['", $private) . '\']=$value;');
-		} else {
-			$array = str_replace('[\'\']', '[]', '$privates[\'' . join("']['", $private) . '\']=\'' . $value . '\';');
-		}
-		eval($array);
-		if (isset($this->_private[$name])) {
-			if (!is_array($this->_private[$name])) {
-				unset($this->_private[$name]);
-				$this->_private[$name] = $privates;
-			} else {
-				$this->_private[$name] = array_merge_recursive($this->_private[$name], $privates);
-			}
-		} else {
-			$this->_private[$name] = $privates;
-		}
-		return $this->_private;
+	    return $this->set($key, $value);
 	}
 
 	/**
@@ -204,4 +172,14 @@ class Arrays
 		}
 		return $value;
 	}
+
+    /**
+     * 获取通过setPrivate key对应的值
+     *
+     * @param String $key
+     * @return Mix
+     */
+	public function getPrivate($key) {
+	    return $this->get($key);
+    }
 }

+ 1 - 1
src/Qii.php

@@ -88,7 +88,7 @@ class Qii extends Application
      */
     public static function getPrivate($name, $key = '')
     {
-        $private = Psr4::getInstance()->loadClass('\Qii\Config\Arrays')->getPrivate($name);
+        $private = Psr4::getInstance()->loadClass('\Qii\Config\Arrays')->get($name);
         if (preg_match('/^\s*$/', $key)) {
             return $private;
         }