Explorar o código

Merge branch 'master' of http://code.travelzs.com:3000/root/Qii

Jinhui Zhu %!s(int64=6) %!d(string=hai) anos
pai
achega
84271d2592
Modificáronse 5 ficheiros con 67 adicións e 51 borrados
  1. 29 16
      src/Application.php
  2. 11 33
      src/Config/Arrays.php
  3. 1 1
      src/Qii.php
  4. 25 0
      src/Request/Url.php
  5. 1 1
      src/Request/Url/Base.php

+ 29 - 16
src/Application.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace Qii;
 
 use \Qii\Base\Dispatcher;
@@ -12,7 +13,7 @@ use \Qii\Config\Register;
 use \Qii\Config\Consts;
 use \Qii\Config\Setting;
 
-class Application 
+class Application
 {
     /**
      * 存储网站配置文件内容
@@ -27,7 +28,8 @@ class Application
     /**
      * @var string $workspace 工作目录
      */
-    private static $workspace = './';/**
+    private static $workspace = './';
+    /**
      * @var string $env 环境变量
      */
     public static $env = 'product';
@@ -45,25 +47,25 @@ class Application
      */
     public $dispatcher = null;
 
-	public function __construct()
-	{
+    public function __construct()
+    {
         $this->helper = Psr4::getInstance()->loadClass('\Qii\Autoloader\Helper');
-	}
+    }
 
     /**
      * 初始化本实例对象
      *
      * @return object
      */
-	public static function getInstance()
-	{
+    public static function getInstance()
+    {
         $args = func_get_args();
         if (count($args) > 0) {
             $className = array_shift($args);
             return Psr4::getInstance($className);
         }
-	    return Factory::getInstance('\Qii\Application');
-	}
+        return Factory::getInstance('\Qii\Application');
+    }
 
     /**
      * 设置网站运行环境
@@ -76,6 +78,7 @@ class Application
         self::$env = $env;
         return $this;
     }
+
     /**
      * 设置缓存文件路径
      * @param string $path 缓存路径
@@ -120,6 +123,7 @@ class Application
 
         return $this;
     }
+
     /**
      * 获取指定路径的缓存绝对路径
      * @param string $path 路径
@@ -129,12 +133,13 @@ class Application
     {
         if (self::$workspace != '') return self::$workspace . DS . $path;
         $dir = '';
-        $workspace = sr4::getInstance()->getNamespace('workspace');
+        $workspace = Psr4::getInstance()->getNamespace('workspace');
         foreach ($workspace AS $dir) {
             if (is_dir($dir)) $dir = $dir;
         }
         return $dir . DS . $path;
     }
+
     /**
      * 获取网站运行环境
      *
@@ -144,6 +149,7 @@ class Application
     {
         return self::$env;
     }
+
     /**
      * 获取当前工作目录
      */
@@ -151,6 +157,7 @@ class Application
     {
         return self::$workspace;
     }
+
     /**
      * 获取网站的配置文件
      * @return Config\Mix
@@ -208,7 +215,7 @@ class Application
         Register::rewriteConfig($iniFile, $key, $val);
         return $this;
     }
-    
+
     /**
      * 设置指定的前缀是否使用命名空间
      * @param string $prefix 前缀
@@ -275,6 +282,7 @@ class Application
         );
         return $this;
     }
+
     /**
      * 设置缓存
      *
@@ -299,7 +307,8 @@ class Application
      * @param String $cache 缓存的内容
      * @return multitype:multitype:Ambigous <>
      */
-    public function getCachePolicy($cache) {
+    public function getCachePolicy($cache)
+    {
         $data = array();
         if (!$cache) return $data;
         $cacheInfo = Register::getAppConfigure(Register::get(Consts::APP_INI_FILE), $cache);
@@ -312,6 +321,7 @@ class Application
         }
         return $data;
     }
+
     /**
      * 设置view
      *
@@ -319,7 +329,8 @@ class Application
      * @param array $policy
      * @return mixed
      */
-    public function setView($engine = 'smarty', $policy = array()) {
+    public function setView($engine = 'smarty', $policy = array())
+    {
         $viewConfigure = \Qii::appConfigure('view');
         //如果之前实例化过相同的就不再实例化
         if (!$engine) $engine = $viewConfigure['engine'];
@@ -331,6 +342,7 @@ class Application
         $viewEngine->setView($engine, $policy);
         return $viewEngine;
     }
+
     /**
      * 设置数据库使用的文件
      *
@@ -405,6 +417,7 @@ class Application
         $this->request->setActionName($rewrite['action']);
         return $this;
     }
+
     /**
      * sprintf 格式化语言错误信息内容
      *
@@ -422,8 +435,8 @@ class Application
      * @return $this
      * @throws \Exception
      */
-	public function run()
-	{
+    public function run()
+    {
         $this->helper->load(self::$workspace);
         $this->dispatcher = Psr4::getInstance()->loadClass('\Qii\Base\Dispatcher');
         if (!$this->dispatcher instanceof \Qii\Base\Dispatcher) {
@@ -448,5 +461,5 @@ class Application
         $this->dispatcher->dispatch();
         $this->request->setDispatched(true);
         return $this;
-	}
+    }
 }

+ 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;
         }

+ 25 - 0
src/Request/Url.php

@@ -60,6 +60,31 @@ class Url
         return \Qii\Request\Url::getInstance($rewriteRule)->request->getCurrentURL();
     }
 
+    /**
+     * 返回web host
+     * @return mixed
+     */
+    public static function getHost()
+    {
+        $rewriteRule = \Qii::getInstance()->appConfigure(\Qii\Config\Consts::APP_SITE_METHOD);
+        return \Qii\Request\Url::getInstance($rewriteRule)->request->getWebHost();
+    }
+
+    /**
+     * 获取subdomain
+     * @return string
+     */
+    public static function getSubdomain()
+    {
+        $rewriteRule = \Qii::getInstance()->appConfigure(\Qii\Config\Consts::APP_SITE_METHOD);
+        $host = \Qii\Request\Url::getInstance($rewriteRule)->request->getWebHost();
+        $domain = parse_url($host)['host'] ?? "";
+
+        if(stristr($domain,".")) {
+            return explode(".", $domain)[0];
+        }
+        return "";
+    }
     /**
      * 获取网站路径的URL
      * @return string

+ 1 - 1
src/Request/Url/Base.php

@@ -182,7 +182,7 @@ abstract class Base
     public function getPath($path = '')
     {
         if (empty($path)) {
-            $path = $_SERVER['SCRIPT_NAME'];
+            $path = $_SERVER['REQUEST_URI'];
         }
         return substr($path, 0, (strrpos($path, '/')));
     }