瀏覽代碼

optimization

zhujinhui 2 年之前
父節點
當前提交
8f64265aa5
共有 55 個文件被更改,包括 404 次插入798 次删除
  1. 0 21
      composer.lock
  2. 7 5
      src/Application.php
  3. 0 2
      src/Autoloader/Factory.php
  4. 8 4
      src/Autoloader/Helper.php
  5. 19 19
      src/Autoloader/Import.php
  6. 7 5
      src/Autoloader/Instance.php
  7. 4 4
      src/Autoloader/Loader.php
  8. 20 12
      src/Autoloader/Psr4.php
  9. 3 5
      src/Base/Controller.php
  10. 9 5
      src/Base/Dispatcher.php
  11. 9 11
      src/Base/Request.php
  12. 15 13
      src/Base/Response.php
  13. 2 3
      src/Base/Rules.php
  14. 8 4
      src/Cache/Apcu.php
  15. 16 13
      src/Cache/File.php
  16. 2 2
      src/Cache/Intf.php
  17. 5 2
      src/Cache/Loader.php
  18. 6 6
      src/Cache/Memcached.php
  19. 23 18
      src/Cache/Redis.php
  20. 11 11
      src/Cache/XCache.php
  21. 45 45
      src/Conf/namespace.php
  22. 1 1
      src/Config/Mine.php
  23. 4 4
      src/Config/Register.php
  24. 1 1
      src/Config/Setting.php
  25. 16 13
      src/Driver/Base.php
  26. 5 2
      src/Driver/ConnBase.php
  27. 7 3
      src/Driver/Easy.php
  28. 3 1
      src/Driver/Fields.php
  29. 1 1
      src/Driver/Intf.php
  30. 17 12
      src/Driver/Model.php
  31. 1 1
      src/Driver/Observer.php
  32. 12 10
      src/Driver/Response.php
  33. 6 3
      src/Driver/Rules.php
  34. 5 2
      src/Driver/TraitCache.php
  35. 1 3
      src/Driver/TraitDatabase.php
  36. 14 9
      src/Functions/Funcs.php
  37. 0 448
      src/Library/Chrome.php
  38. 6 7
      src/Logger/Instance.php
  39. 1 1
      src/Logger/Writer.php
  40. 1 1
      src/Plugin/Intf.php
  41. 3 3
      src/Plugin/Plugin.php
  42. 19 21
      src/Qii.php
  43. 13 8
      src/Request/Http.php
  44. 1 1
      src/Request/Sample.php
  45. 9 6
      src/Request/Url.php
  46. 3 1
      src/Request/Url/Base.php
  47. 3 1
      src/Response/Cli.php
  48. 3 1
      src/Response/Http.php
  49. 7 5
      src/Router/Parse.php
  50. 1 1
      src/Router/Parse/Normal.php
  51. 1 3
      src/Router/Parse/Regx.php
  52. 4 4
      src/View/Includes.php
  53. 3 1
      src/View/Loader.php
  54. 10 8
      src/View/Render.php
  55. 3 1
      src/View/Requires.php

+ 0 - 21
composer.lock

@@ -1,21 +0,0 @@
-{
-    "_readme": [
-        "This file locks the dependencies of your project to a known state",
-        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
-        "This file is @generated automatically"
-    ],
-    "content-hash": "6dbd294dc8e4c5ef89baa4c4c62ee9e7",
-    "packages": [],
-    "packages-dev": [],
-    "aliases": [],
-    "minimum-stability": "dev",
-    "stability-flags": [],
-    "prefer-stable": false,
-    "prefer-lowest": false,
-    "platform": {
-        "php": ">=5.4",
-        "ext-gd": ">=2.1.0"
-    },
-    "platform-dev": [],
-    "plugin-api-version": "2.2.0"
-}

+ 7 - 5
src/Application.php

@@ -12,6 +12,8 @@ use \Qii\Autoloader\Instance;
 use \Qii\Config\Register;
 use \Qii\Config\Consts;
 use \Qii\Config\Setting;
+use Qii\Exceptions\FileNotFound;
+use Qii\Request\Url;
 
 class Application
 {
@@ -182,7 +184,7 @@ class Application
         if ($env == '') $env = $this->getEnv();
         $ini = Psr4::getInstance()->getFileByPrefix($ini);
         $this->setAppIniFile($ini);
-        if (!Register::setAppConfigure($ini, $env)) throw new \Qii\Exceptions\FileNotFound($ini, 404);
+        if (!Register::setAppConfigure($ini, $env)) throw new FileNotFound($ini, 404);
         //载入request方法
         $this->request = Psr4::getInstance()->loadClass('\Qii\Request\Http');
         Setting::getInstance()->setDefaultTimeZone();
@@ -348,7 +350,7 @@ class Application
      * 设置数据库使用的文件
      *
      * @param $iniFile
-     * @throws \Qii_Exceptions_Overwrite
+     * @throws \Qii\Exceptions\Overwrite
      */
     public function setDBIniFile($iniFile)
     {
@@ -359,7 +361,7 @@ class Application
      * 获取当前数据库文件
      *
      * @return \Qii_Mix
-     * @throws \Qii_Exceptions_Variable
+     * @throws \Qii\Exceptions\Variable
      */
     public function getDBIniFile()
     {
@@ -379,7 +381,7 @@ class Application
             Psr4::getInstance()->getFileByPrefix($ini),
             $env)
         ) {
-            throw new \Qii\Exceptions\FileNotFound($ini, 404);
+            throw new FileNotFound($ini, 404);
         }
         return $this;
     }
@@ -403,7 +405,7 @@ class Application
         $rewrite = Psr4::loadStatic(
             '\Qii\Router\Parse',
             'get',
-            \Qii\Request\Url::getPathInfo(),
+            Url::getPathInfo(),
             $this->request->controller,
             $this->request->action,
             $this->request->url->get(2)

+ 0 - 2
src/Autoloader/Factory.php

@@ -1,8 +1,6 @@
 <?php
 namespace Qii\Autoloader;
 
-use \Qii\Exceptions;
-
 class Factory
 {
     /**

+ 8 - 4
src/Autoloader/Helper.php

@@ -1,6 +1,8 @@
 <?php
 namespace Qii\Autoloader;
 
+use Qii\Exceptions\CallUndefinedClass;
+
 /**
  * Helper 将自动注册到系统 Helper中,直接调用即可
  *
@@ -11,7 +13,7 @@ class Helper
 {
     const VERSION = '1.2';
     /**
-     * @var $helpers helper类
+     * @var array $helpers helper类
      */
     public static $helpers = array();
 
@@ -24,6 +26,7 @@ class Helper
      * 使用属性返回helper类
      * @param string $name 不带helper\的类名
      * @return object
+     * @throws
      */
     public function __get($name)
     {
@@ -35,11 +38,12 @@ class Helper
      * 获取helper类,如果没有实例化就抛出异常
      * @param string $helper
      * @return object
+     * @throws CallUndefinedClass
      */
     public function get($helper)
     {
         if (isset(self::$helpers[$helper])) return self::$helpers[$helper];
-        throw new \Qii\Exceptions\CallUndefinedClass(\Qii::i('1105', $helper), __LINE__);
+        throw new CallUndefinedClass(\Qii::i('1105', $helper), __LINE__);
     }
 
     /*
@@ -55,11 +59,11 @@ class Helper
             return;
         }
         foreach (glob(str_replace("//", DS, $appPath . DS . 'helper' . DS . '*.php'), GLOB_BRACE) AS $file) {
-            if(\Qii\Autoloader\Import::requires($file)){
+            if(Import::requires($file)){
                 //如果里边包含class的话就将class注册到Qii::instance('class');
                 $className = 'helper\\'. pathinfo($file)['filename'];
                 if (!isset(self::$helpers[$className]) && class_exists($className, false)) {
-                    self::$helpers[$className] = \Qii\Autoloader\Psr4::getInstance()->instance($className);
+                    self::$helpers[$className] = Psr4::getInstance()->instance($className);
                 }
             }
         }

+ 19 - 19
src/Autoloader/Import.php

@@ -1,6 +1,8 @@
 <?php
 namespace Qii\Autoloader;
 
+use Qii\Exceptions\FileNotFound;
+
 class Import
 {
     const VERSION = '1.3';
@@ -10,7 +12,7 @@ class Import
     /**
      * require文件
      *
-     * @param string $file 需要require的文件
+     * @param array|string $file 需要require的文件
      * @return array|bool|void
      */
     public static function requires($file)
@@ -22,18 +24,19 @@ class Import
         }
         $file = str_replace(DS . DS , DS, str_replace(array('\\', '/'), DS, $file));
         if (self::getFileLoaded($file)) return true;
-        if (file_exists($file)) {
-            self::setFileLoaded($file);
-            require $file;
-            return true;
+        if (!file_exists($file)) {
+            return false;
         }
-        return false;
+        self::setFileLoaded($file);
+        require $file;
+        return true;
     }
 
     /**
      * 包含文件
-     * @param string $file 文件路径
-     * @return mix
+     * @param array | string $file 文件路径
+     * @return array
+     * @throws
      */
     public static function includes($file)
     {
@@ -44,15 +47,12 @@ class Import
         }
         $file = str_replace(array('\\', '/'), DS, $file);
         if (self::getIncludeFiles($file) !== null) self::getIncludeFiles($file);
-        if (file_exists($file)) {
-            $configure = include($file);
-            self::setIncludeFiles($file, $configure);
-            return $configure;
-        }else{
-            //print_r(debug_backtrace());
-            throw new \Qii\Exceptions\FileNotFound($file, 404);
+        if (!file_exists($file)) {
+            throw new FileNotFound($file, 404);
         }
-        return false;
+        $configure = include($file);
+        self::setIncludeFiles($file, $configure);
+        return $configure;
     }
 
     /**
@@ -63,18 +63,18 @@ class Import
      */
     public static function requireByClass($className)
     {
-        return \Qii\Autoloader\Psr4::getInstance()->loadFileByClass($className);
+        return Psr4::getInstance()->loadFileByClass($className);
     }
 
     /**
      * 载入文件夹中所有文件
      *
      * @param string $dir 目录
-     * @throws Qii\Exceptions\FileNotFound
+     * @throws FileNotFound
      */
     public static function requireByDir($dir)
     {
-        if (!is_dir($dir)) throw new \Qii\Exceptions\FileNotFound($dir, 404);
+        if (!is_dir($dir)) throw new FileNotFound($dir, 404);
         $files = self::findFiles($dir, array('php'));
         if (isset($files['php'])) self::requires($files['php']);
     }

+ 7 - 5
src/Autoloader/Instance.php

@@ -1,5 +1,7 @@
 <?php
 namespace Qii\Autoloader;
+use Qii\Exceptions\CallUndefinedClass;
+
 /**
  * Instance类
  * @author Jinhui Zhu<jinhui.zhu@live.cn>2015-10-22 19:45
@@ -14,7 +16,7 @@ class Instance
 {
     const VERSION = '1.2';
     /**
-     * @var APP_LOAD_PREFIX 保存类到以APP_LOAD_PREFIX开头的key中
+     * @var string APP_LOAD_PREFIX 保存类到以APP_LOAD_PREFIX开头的key中
      */
     const APP_LOAD_PREFIX = '__qii_instance';
     /**
@@ -30,7 +32,7 @@ class Instance
     public static function getInstance($className)
     {
         if (isset(self::$loadedClass[self::APP_LOAD_PREFIX . $className])) return self::$loadedClass[self::APP_LOAD_PREFIX . $className];
-        throw new \Qii\Exceptions\CallUndefinedClass(\Qii::i('1105', $className), __LINE__);
+        throw new CallUndefinedClass(\Qii::i('1105', $className), __LINE__);
     }
 
     /**
@@ -40,7 +42,7 @@ class Instance
     {
         $args = func_get_args();
         $className = array_shift($args);
-        if (!class_exists($className, false)) throw new \Qii\Exceptions\CallUndefinedClass(\Qii::i('1102', $className), __LINE__);
+        if (!class_exists($className, false)) throw new CallUndefinedClass(\Qii::i('1102', $className), __LINE__);
         if (isset(self::$loadedClass[self::APP_LOAD_PREFIX . $className])
             && self::$loadedClass[self::APP_LOAD_PREFIX . $className]
         ) return self::$loadedClass[self::APP_LOAD_PREFIX . $className];
@@ -65,8 +67,8 @@ class Instance
     {
         $args = func_get_args();
         $className = array_shift($args);
-        $className = \Qii\Autoloader\Psr4::getInstance()->getClassName($className);
-        \Qii\Autoloader\Psr4::getInstance()->loadFileByClass($className);
+        $className = Psr4::getInstance()->getClassName($className);
+        Psr4::getInstance()->loadFileByClass($className);
         return call_user_func_array(array('\Qii\Autoloader\Instance', 'initialize'), array_merge(array($className), $args));
     }
 }

+ 4 - 4
src/Autoloader/Loader.php

@@ -9,11 +9,11 @@ class Loader
 
     const VERSION = '1.2';
     /**
-     * @var $loaded 保存已经加载过的类实例
+     * @var array $loaded 保存已经加载过的类实例
      */
     private $loaded;
     /**
-     * @var $lastCall 最后一次访问的方法
+     * @var string $lastCall 最后一次访问的方法
      */
     private $lastCall;
 
@@ -41,7 +41,7 @@ class Loader
      */
     public static function Instance()
     {
-        return \Qii\Autoloader\Instance::instance('\Qii\Autoloader\Loader');
+        return Instance::instance('\Qii\Autoloader\Loader');
     }
 
     /**
@@ -56,7 +56,7 @@ class Loader
         $class = array_shift($args);
         if ($this->lastCall) {
             $className = $this->lastCall . '\\' . $method;
-            \Qii\Autoloader\Import::requireByClass($className);
+            Import::requireByClass($className);
         } else {
             $className = $method . '\\' . $class;
         }

+ 20 - 12
src/Autoloader/Psr4.php

@@ -1,6 +1,8 @@
 <?php
 namespace Qii\Autoloader;
 
+use Qii\Exceptions\FileNotFound;
+
 /**
  * Psr4 规范
  *
@@ -205,12 +207,7 @@ class Psr4
      */
     public function getFileByPrefix($fileName)
     {
-        $fileName = str_replace(array('/', '\\'), DS, $fileName);
-        $prefixes = explode(DS, $fileName, 2);
-        $dirs = isset($this->prefixes['workspace\\']) ? $this->prefixes['workspace\\'] : array();
-        if (count($prefixes) == 2) {
-            if (isset($this->prefixes[$prefixes[0]])) $dirs = $this->prefixes[$prefixes[0]];
-        }
+        $dirs = $this->getPrefixAndDirs($fileName);
         foreach ($dirs as $baseDir) {
             if (is_file($baseDir . DS . $fileName)) {
                 return $baseDir . DS . $fileName;
@@ -220,18 +217,28 @@ class Psr4
     }
 
     /**
-     * 获取指定文件夹路径
-     * @param string $folder 路径
-     * @return string 路径
+     * 通过前缀获取路径
+     *
+     * @param $folder
+     * @return array|mixed
      */
-    public function getFolderByPrefix($folder)
-    {
+    protected function getPrefixAndDirs($folder) {
         $fileName = str_replace(array('/', '\\'), DS, $folder);
         $prefixes = explode(DS, $fileName, 2);
         $dirs = isset($this->prefixes['workspace\\']) ? $this->prefixes['workspace\\'] : array();
         if (count($prefixes) == 2) {
             if (isset($this->prefixes[$prefixes[0]])) $dirs = $this->prefixes[$prefixes[0]];
         }
+        return $dirs;
+    }
+    /**
+     * 获取指定文件夹路径
+     * @param string $folder 路径
+     * @return string 路径
+     */
+    public function getFolderByPrefix($folder)
+    {
+        $dirs = $this->getPrefixAndDirs($folder);
         foreach ($dirs as $baseDir) {
             return $baseDir . DS . $folder;
         }
@@ -270,6 +277,7 @@ class Psr4
      * 通过类名加载文件
      * @param string $class 类名
      * @return string 文件路径
+     * @throws FileNotFound
      */
     public function loadFileByClass($class)
     {
@@ -279,7 +287,7 @@ class Psr4
         if(!$this->searchMappedFile($class))
         {
             $notLoaded = isset(self::$lastErrorLoadedFile[$class]) ? self::$lastErrorLoadedFile[$class] : self::getClassName($class);
-            throw new \Qii\Exceptions\FileNotFound($notLoaded, 404);
+            throw new FileNotFound($notLoaded, 404);
         }
     }
 

+ 3 - 5
src/Base/Controller.php

@@ -5,11 +5,9 @@
 
 namespace Qii\Base;
 
+use Qii\Autoloader\Factory;
 use \Qii\Autoloader\Psr4;
 
-use \Qii\Config\Register;
-use \Qii\Config\Consts;
-
 /**
  * Qii_Controller_Abstract class
  * @author Zhu Jinhui
@@ -78,8 +76,8 @@ abstract class Controller
         $this->request = Psr4::getInstance()->loadClass('\Qii\Request\Http');
         $this->controllerId = $this->request->controller;
         $this->actionId = $this->request->action;
-        $this->language = \Qii\Autoloader\Factory::getInstance('\Qii\Language\Loader');
-        $this->response = \Qii\Autoloader\Factory::getInstance('\Qii\Base\Response');
+        $this->language = Factory::getInstance('\Qii\Language\Loader');
+        $this->response = Factory::getInstance('\Qii\Base\Response');
         $this->cache = new \stdClass();
         //载入model
         if ($this->enableDB) {

+ 9 - 5
src/Base/Dispatcher.php

@@ -1,8 +1,11 @@
 <?php
 namespace Qii\Base;
 
+use Qii\Autoloader\Psr4;
 use \Qii\Config\Register;
 use \Qii\Config\Consts;
+use Qii\Exceptions\MethodNotFound;
+use Qii\Request\Http;
 
 class Dispatcher
 {
@@ -18,9 +21,9 @@ class Dispatcher
     }
     /**
      * 设置请求
-     * @param \Qii\Request\Http $request 当前请求
+     * @param Http $request 当前请求
      */
-    public function setRequest(\Qii\Request\Http $request)
+    public function setRequest(Http $request)
     {
         $this->request = $request;
         return $this;
@@ -31,6 +34,7 @@ class Dispatcher
      * @param string $controller
      * @param string $action
      * @return mixed
+     * @throws
      */
     public function dispatch($controller = '', $action = '')
     {
@@ -48,7 +52,7 @@ class Dispatcher
             $funcArgs = array_slice($args, 2);
         }
         array_unshift($funcArgs, $controllerName);
-        $psr4 = \Qii\Autoloader\Psr4::getInstance();
+        $psr4 = Psr4::getInstance();
         $controllerCls = call_user_func_array(array($psr4, 'loadClass'), $funcArgs);
 
         $method = new \ReflectionMethod($this, 'dispatch');
@@ -82,7 +86,7 @@ class Dispatcher
                 call_user_func_array(array($this->actionCls, 'initialization'), array($this->actionCls));
             }
             if (!method_exists($this->actionCls, 'run')) {
-                throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $this->controllerCls->actions[$action] . '->run'), __LINE__);
+                throw new MethodNotFound(\Qii::i(1101, $this->controllerCls->actions[$action] . '->run'), __LINE__);
             }
             $response = call_user_func_array(array($this->actionCls, 'run'), array_slice($funcArgs, 1));
         } else {
@@ -93,7 +97,7 @@ class Dispatcher
             array_shift($funcArgs);
             $actionName = $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX);
             if (!method_exists($this->controllerCls, $actionName) && !method_exists($this->controllerCls, '__call')) {
-                throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $controller . '->' . $actionName), __LINE__);
+                throw new MethodNotFound(\Qii::i(1101, $controller . '->' . $actionName), __LINE__);
             }
             $this->controllerCls->response = $response = call_user_func_array(array($this->controllerCls, $actionName), $funcArgs);
         }

+ 9 - 11
src/Base/Request.php

@@ -450,15 +450,15 @@ abstract class Request
      * setRequestUri
      *
      * @param string $uri
-     * @return boolean | Qii_Request_Abstract
+     * @return boolean | Request
      */
     public function setRequestUri($uri)
     {
         if (is_string($uri)) {
             $this->uri = $uri;
-            return $this;
         }
-        return false;
+
+        return $this;
     }
 
     /**
@@ -487,23 +487,22 @@ abstract class Request
      * setDispatched
      *
      * @param boolean $flag
-     * @return boolean | Qii_Request_Abstract
+     * @return Request
      */
     public function setDispatched($flag = true)
     {
         if (is_bool($flag)) {
             $this->dispatched = $flag;
-            return $this;
         }
-        return false;
+        return $this;
     }
 
     /**
      * 设置dispatcher
      *
-     * @param Qii_Controller_Dispatcher $dispatcher
+     * @param Dispatcher $dispatcher
      */
-    public function setDispatcher(\Qii\Base\Dispatcher $dispatcher)
+    public function setDispatcher(Dispatcher $dispatcher)
     {
         $this->dispatcher = $dispatcher;
     }
@@ -529,9 +528,8 @@ abstract class Request
     {
         if (is_bool($flag)) {
             $this->routed = $flag;
-            return $this;
         }
-        return false;
+        return $this;
     }
 
     /**
@@ -571,7 +569,7 @@ abstract class Request
             return true;
         } elseif ($requestUri && is_string($requestUri)) {
             $scriptFileName = $this->getServer('SCRIPT_FILENAME');
-
+            $basename = "";
             do {
                 if ($scriptFileName && is_string($scriptFileName)) {
                     $fileName = basename($scriptFileName, \Qii::getInstance()->appConfigure('ext', '.php'));

+ 15 - 13
src/Base/Response.php

@@ -2,6 +2,8 @@
 
 namespace Qii\Base;
 
+use Qii\Response\Cli;
+
 class Response
 {
     /**
@@ -32,7 +34,7 @@ class Response
     
     /**
      * Determine to send the headers or not
-     * @var unknown_type
+     * @var bool $_sendHeader
      */
     protected $_sendHeader = false;
     
@@ -49,15 +51,15 @@ class Response
      */
     public function setRender(\Qii\View\Intf $render)
     {
-        \Qii\Base\Response::$render = $render;
+        Response::$render = $render;
     }
     
     /**
      * Append content to the body content
      *
-     * @param string $content
+     * @param string $body
      * @param string $key
-     * @return Qii_Response_Abstract
+     * @return Response
      */
     public function appendBody($body, $key = NULL)
     {
@@ -92,7 +94,7 @@ class Response
     /**
      * Clear headers
      *
-     * @return Qii\Response\Abstract
+     * @return Response
      */
     public function clearHeaders()
     {
@@ -129,7 +131,7 @@ class Response
      *
      * @param string $body
      * @param string $key
-     * @return Qii_Response_Abstract
+     * @return Response
      */
     public function prependBody($body, $key = null)
     {
@@ -173,16 +175,16 @@ class Response
                     if (is_array($this->data['body'])) {
                         $body = '';
                         if (isset($this->data['body']['render']) && $this->data['body']['render'] instanceof \Qii\View\Intf) {
-                            \Qii\Base\Response::$render = $this->data['body']['render'];
+                            Response::$render = $this->data['body']['render'];
                         }
                         
-                        if (\Qii\Base\Response::$render != null && \Qii\Base\Response::$render instanceof \Qii\View\Intf) {
+                        if (Response::$render != null && Response::$render instanceof \Qii\View\Intf) {
                             $tplData = isset($this->data['body']['tplData']) ? $this->data['body']['tplData'] : [];
-                            \Qii\Base\Response::$render->assign($tplData);
-                            $body = \Qii\Base\Response::$render->fetch($this->data['body']['tpl']);
+                            Response::$render->assign($tplData);
+                            $body = Response::$render->fetch($this->data['body']['tpl']);
                         }
                     }
-                    echo(IS_CLI ? (new \Qii\Response\Cli())->stdout($body) : $body);
+                    echo(IS_CLI ? (new Cli())->stdout($body) : $body);
                     break;
             }
             return;
@@ -191,7 +193,7 @@ class Response
             $this->sendHeaders();
         }
         foreach ($this->body as $key => $body) {
-            echo IS_CLI ? new \Qii\Response\Cli($body) : $body;
+            echo IS_CLI ? new Cli($body) : $body;
         }
     }
     
@@ -225,7 +227,7 @@ class Response
      * @param string $name
      * @param string $value
      * @param boolean $replace
-     * @return Qii_Response_Abstract
+     * @return Response
      */
     public function setHeader($name, $value, $replace = false)
     {

+ 2 - 3
src/Base/Rules.php

@@ -34,7 +34,6 @@ class Rules
     public function __construct()
     {
         $this->validate = \_loadClass('\Qii\Library\Validate');
-        $this->constants();
         $this->clean();
     }
 
@@ -136,7 +135,7 @@ class Rules
         {
             $this->$method();
         }
-        if(!$method) throw new Exception(__METHOD__ . ' undefined.', 1);
+        throw new Exception(__METHOD__ . ' undefined.', 1);
     }
     /**
      * 添加规则
@@ -268,7 +267,7 @@ class Rules
     }
     /**
      * 验证数据,验证将返回数据及验证结果
-     * @return bool
+     * @return array
      */
     public function verify()
     {

+ 8 - 4
src/Cache/Apcu.php

@@ -1,7 +1,7 @@
 <?php
 namespace Qii\Cache;
 
-class Apcu implements Qii_Cache_Intf
+class Apcu implements Intf
 {
     const VERSION = '1.2';
     public $policy = array('life_time' => 3600);//设置目录、过期时间、文件前缀
@@ -13,13 +13,13 @@ class Apcu implements Qii_Cache_Intf
         }
     }
 
-    public function set($key, $value, $policy)
+    public function set($key, $data, array $policy = null)
     {
         if(is_array($policy))
         {
             $this->policy = array_merge($this->policy, $policy);
         }
-        return apcu_store($key, $value, $this->policy['life_time']);
+        return apcu_store($key, $data, $this->policy['life_time']);
     }
 
     public function get($key)
@@ -32,8 +32,12 @@ class Apcu implements Qii_Cache_Intf
         return apcu_exists($key);
     }
     
-    public function del($key)
+    public function remove($key)
     {
         return apcu_delete($key);
     }
+
+    public function clean() {
+        return apcu_clear_cache();
+    }
 }

+ 16 - 13
src/Cache/File.php

@@ -1,4 +1,8 @@
 <?php
+
+use Qii\Autoloader\Psr4;
+use Qii\Exceptions\AccessDenied;
+
 /**
  * @author Jinhui Zhu<jinhui.zhu@live.cn> 2015-10-26 21:44
  *
@@ -9,7 +13,7 @@
  * $this->cache->get(id);
  * $this->cache->remove(id);
  */
-class Qii_Cache_File implements Qii_Cache_Intf
+class File implements Intf
 {
     const VERSION = '1.2';
     public $policy = array('path' => 'tmp', 'life_time' => 3600, 'prefix' => 'file');//设置目录、过期时间、文件前缀
@@ -44,13 +48,13 @@ class Qii_Cache_File implements Qii_Cache_Intf
     {
         if (!is_dir($this->policy['path'])) mkdir($this->policy['path'], 0777);
         if (is_dir($this->policy['path'])) {
-            $this->policy['path'] = \Qii_Autoloader_Psr4::realpath($this->policy['path']);
+            $this->policy['path'] = Psr4::realpath($this->policy['path']);
         } else {
             \Qii::setError(false, __LINE__, 1401, $this->policy['path']);
         }
         //如果在系统目录就不让保存
         if (in_array($this->policy['path'], $this->exclude)) {
-            throw  new \Qii_Execptions_AccessDenied($this->policy['path']);
+            throw  new AccessDenied($this->policy['path']);
         }
     }
 
@@ -63,8 +67,7 @@ class Qii_Cache_File implements Qii_Cache_Intf
     public function getFileName($id)
     {
         $fileName = $this->policy['path'] . '/' . $this->policy['prefix'] . '.' . $id . '.' . (time() + $this->policy['life_time']);
-        $fileName = $fileName . '.' . md5($fileName);
-        return $fileName;
+        return $fileName . '.' . md5($fileName);
     }
 
     /**
@@ -81,35 +84,35 @@ class Qii_Cache_File implements Qii_Cache_Intf
     /**
      * 缓存数据
      *
-     * @param $id
+     * @param $key
      * @param $data
      * @param array|null $policy
      * @return bool|int|void
      * @throws AccessDeniedExecption
      */
-    public function set($id, $data, array $policy = null)//设置
+    public function set($key, $data, array $policy = null)//设置
     {
         if (!empty($policy)) {
             $this->policy = array_merge($this->policy, $policy);
         }
         $this->checkIsSave();
-        $fileName = $this->getFileName($id);
+        $fileName = $this->getFileName($key);
         //检查文件是否存在,存在就先删除再保存
-        $this->remove($id);
+        $this->remove($key);
         return file_put_contents($fileName, serialize($data), LOCK_EX);
     }
 
     /**
      * 获取指定key的缓存
      *
-     * @param $id
+     * @param $key
      * @return mixed|void
      * @throws AccessDeniedExecption
      */
-    public function get($id)
+    public function get($key)
     {
         $this->checkIsSave();
-        $fileArray = glob($this->policy['path'] . '/' . $this->policy['prefix'] . '.' . $id . '.*');
+        $fileArray = glob($this->policy['path'] . '/' . $this->policy['prefix'] . '.' . $key . '.*');
         //检查文件是否存在
         if (count($fileArray) == 0) {
             return;
@@ -145,7 +148,7 @@ class Qii_Cache_File implements Qii_Cache_Intf
     public function clean()
     {
         $this->checkIsSave();
-        //禁止清除Qii目录文件
+        //禁止清除目录下的缓存文件
         $handle = opendir($this->policy['path']);
         if ($handle) {
             while ($file = readdir($handle)) {

+ 2 - 2
src/Cache/Intf.php

@@ -11,9 +11,9 @@ interface Intf
 {
     public function __construct(array $policy = null);
 
-    public function set($id, $data, array $policy = null);//设置
+    public function set($key, $data, array $policy = null);//设置
 
-    public function get($id);//获取指定key的缓存
+    public function get($key);//获取指定key的缓存
 
     public function remove($key);//移除指定key的缓存
 

+ 5 - 2
src/Cache/Loader.php

@@ -6,6 +6,9 @@
  */
 namespace Qii\Cache;
 
+use Qii\Autoloader\Import;
+use Qii\Autoloader\Psr4;
+
 class Loader
 {
     const VERSION = '1.2';
@@ -24,7 +27,7 @@ class Loader
      */
     public function initialization($policy)
     {
-        return \Qii\Autoloader\Psr4::getInstance()->loadClass('Qii\Cache\\' . ucwords($this->cache), $policy);
+        return Psr4::getInstance()->loadClass('Qii\Cache\\' . ucwords($this->cache), $policy);
     }
 
     /**
@@ -39,6 +42,6 @@ class Loader
         if (!is_file($cacheFile)) {
             throw new \Exception('Unsupported cache class '. $cacheFile);
         }
-        \Qii\Autoloader\Import::requires($cacheFile);
+        Import::requires($cacheFile);
     }
 }

+ 6 - 6
src/Cache/Memcached.php

@@ -117,13 +117,13 @@ class Memcached implements Intf
     /**
      * 读取缓存,失败或缓存撒失效时返回 false
      *
-     * @param string $id
+     * @param string $key
      *
      * @return mixed
      */
-    public function get($id)
+    public function get($key)
     {
-        $data = $this->_conn->get($id);
+        $data = $this->_conn->get($key);
         if($this->_conn instanceof \Memcache || $this->_conn instanceof \Memcached){
             $data = unserialize($data);
         }
@@ -133,12 +133,12 @@ class Memcached implements Intf
     /**
      * 删除指定的缓存
      *
-     * @param string $id
+     * @param string $key
      * @return boolean
      */
-    public function remove($id)
+    public function remove($key)
     {
-        return $this->_conn->delete($id);
+        return $this->_conn->delete($key);
     }
 
     /**

+ 23 - 18
src/Cache/Redis.php

@@ -1,7 +1,12 @@
 <?php
 namespace Qii\Cache;
 
-\Qii\Autoloader\Import::requires(array(dirname(__FILE__) . DS . 'Redis/Client.php', dirname(__FILE__) . DS . 'Redis/Cluster.php'));
+use Qii\Autoloader\Import;
+use Qii\Cache\Redis\Cluster;
+use Qii\Exceptions\Errors;
+use Qii\Exceptions\MethodNotFound;
+
+Import::requires(array(dirname(__FILE__) . DS . 'Redis/Client.php', dirname(__FILE__) . DS . 'Redis/Cluster.php'));
 
 /**
  * PHP 操作 redis
@@ -32,7 +37,7 @@ class Redis implements Intf
     public function __construct(array $policy = null)
     {
         if (!extension_loaded('redis')) {
-            throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1006), __LINE__);
+            throw new MethodNotFound(\Qii::i(1006), __LINE__);
         }
 
 
@@ -44,13 +49,13 @@ class Redis implements Intf
         foreach ($this->policy['servers'] AS $value) {
             $redisServer[] = array('host' => $value['host'], 'port' => $value['port'], 'password' => (isset($value['password']) ? $value['password'] : ''));
         }
-        $this->redis = new \Qii\Cache\Redis\Cluster($redisServer, 128);
+        $this->redis = new Cluster($redisServer, 128);
     }
 
     /**
      * 保存指定key的数据
      */
-    public function hMset($id, $data, array $policy = null)
+    public function hMSet($id, $data, array $policy = null)
     {
         $res = false;
         if (is_array($policy)) {
@@ -63,7 +68,7 @@ class Redis implements Intf
                 $this->redis->expire($id, $this->policy['life_time']);
             }
         } catch (\CredisException $e) {
-            throw new \Qii\Exceptions\Errors(\Qii::i(-1, $e->getMessage()), __LINE__);
+            throw new Errors(\Qii::i(-1, $e->getMessage()), __LINE__);
         }
         return $res;
     }
@@ -71,20 +76,20 @@ class Redis implements Intf
     /**
      * 保存指定key的数据
      */
-    public function set($id, $value, array $policy = null)
+    public function set($key, $data, array $policy = null)
     {
         $res = false;
         if (is_array($policy)) {
             $this->policy = array_merge($this->policy, $policy);
         }
         try {
-            $res = $this->redis->set($id, $value);
+            $res = $this->redis->set($key, $data);
             if (isset($this->policy['life_time']) && $this->policy['life_time'] > 0) {
                 //$this->redis->setTimeout($id, $this->policy['life_time']);
-                $this->redis->expire($id, $this->policy['life_time']);
+                $this->redis->expire($key, $this->policy['life_time']);
             }
         } catch (\CredisException $e) {
-            throw new \Qii\Exceptions\Errors(\Qii::i(-1, $e->getMessage()), __LINE__);
+            throw new Errors(\Qii::i(-1, $e->getMessage()), __LINE__);
         }
 
         return $res;
@@ -92,20 +97,20 @@ class Redis implements Intf
     /**
      * 获取指定key的数据
      */
-    public function hGet($id)
+    public function hGet($key)
     {
-        if ($this->redis->exists($id)) {
-            return $this->redis->hGetAll($id);
+        if ($this->redis->exists($key)) {
+            return $this->redis->hGetAll($key);
         }
         return null;
     }
     /**
      * 获取指定key的数据
      */
-    public function get($id)
+    public function get($key)
     {
-        if ($this->redis->exists($id)) {
-            return $this->redis->get($id);
+        if ($this->redis->exists($key)) {
+            return $this->redis->get($key);
         }
         return null;
     }
@@ -118,10 +123,10 @@ class Redis implements Intf
     /**
      * 删除指定key的数据
      */
-    public function remove($id)
+    public function remove($key)
     {
-        if ($this->redis->exists($id)) {
-            return $this->redis->delete($id);
+        if ($this->redis->exists($key)) {
+            return $this->redis->delete($key);
         }
     }
 

+ 11 - 11
src/Cache/XCache.php

@@ -27,7 +27,7 @@ class XCache implements Intf
     /**
      * 构造函数
      *
-     * @param 默认的缓存策略 $default_policy
+     * @param array $default_policy 默认的缓存策略
      */
     public function __construct(array $default_policy = null)
     {
@@ -39,27 +39,27 @@ class XCache implements Intf
     /**
      * 写入缓存
      *
-     * @param string $id
+     * @param string $key
      * @param mixed $data
      * @param array $policy
      */
-    public function set($id, $data, array $policy = null)
+    public function set($key, $data, array $policy = null)
     {
         $life_time = !isset($policy['life_time']) ? (int)$policy['life_time'] : $this->_default_policy['life_time'];
-        xcache_set($id, $data, $life_time);
+        return xcache_set($key, $data, $life_time);
     }
 
     /**
      * 读取缓存,失败或缓存撒失效时返回 false
      *
-     * @param string $id
+     * @param string $key
      *
      * @return mixed
      */
-    public function get($id)
+    public function get($key)
     {
-        if (xcache_isset($id)) {
-            return xcache_get($id);
+        if (xcache_isset($key)) {
+            return xcache_get($key);
         }
         return false;
     }
@@ -67,11 +67,11 @@ class XCache implements Intf
     /**
      * 删除指定的缓存
      *
-     * @param string $id
+     * @param string $key
      */
-    public function remove($id)
+    public function remove($key)
     {
-        xcache_unset($id);
+        return xcache_unset($key);
     }
 
     public function clean()

+ 45 - 45
src/Conf/namespace.php

@@ -4,50 +4,50 @@
  * @author zjh
  * @version 1.3
  */
-return [
+return array(
     //设置是否使用名称空间
-    'setUseNamespace' => [
-        ['Qii\\', true],
-        ['Qii\Action', true],
-        ['Qii\Autoloader', true],
-        ['Qii\Bootstrap', true],
-        ['Qii\Config', true],
-        ['Qii\Consts', true],
-        ['Qii\Controller', true],
-        ['Qii\Exceptions', true],
-        ['Qii\Language', true],
-        ['Qii\Library', true],
-        ['Qii\Loger', true],
-        ['Qii\Plugin', true],
-        ['Qii\Request', false],
-        ['Qii\Router', true],
-        ['Qii\View', true],
-        ['WhichBrowser', true],
-        ['BigPipe', true],
-        ['Smarty\\', false],
-        ['Smarty\\Internal', false],
-    ],
+    'setUseNamespace' => array(
+        array('Qii\\', true),
+        array('Qii\Action', true),
+        array('Qii\Autoloader', true),
+        array('Qii\Bootstrap', true),
+        array('Qii\Config', true),
+        array('Qii\Consts', true),
+        array('Qii\Controller', true),
+        array('Qii\Exceptions', true),
+        array('Qii\Language', true),
+        array('Qii\Library', true),
+        array('Qii\Loger', true),
+        array('Qii\Plugin', true),
+        array('Qii\Request', false),
+        array('Qii\Router', true),
+        array('Qii\View', true),
+        array('WhichBrowser', true),
+        array('BigPipe', true),
+        array('Smarty\\', false),
+        array('Smarty\\Internal', false),
+    ),
     //设置指定名称空间的文件路径,如按照namespace的不用指定
-    'addNamespace' => [
-        ['Qii\\', Qii_DIR . DS],
-        ['Qii\Action', Qii_DIR . DS . 'Action'],
-        ['Qii\Autoloader', Qii_DIR . DS . 'Autoloader'],
-        ['Qii\Controller', Qii_DIR . DS . 'Controller'],
-        ['Qii\Bootstrap', Qii_DIR . DS . 'Bootstrap'],
-        ['Qii\Config', Qii_DIR . DS . 'Config'],
-        ['Qii\Consts', Qii_DIR . DS . 'Consts'],
-        ['Qii\Exceptions', Qii_DIR . DS . 'Exceptions'],
-        ['Qii\Language', Qii_DIR . DS . 'Language'],
-        ['Qii\Library', Qii_DIR . DS . 'Library'],
-        ['Qii\Logger', Qii_DIR . DS . 'Logger'],
-        ['Qii\Plugin', Qii_DIR . DS . 'Plugin'],
-        ['Qii\Request', Qii_DIR . DS . 'Request'],
-        ['Qii\Response', Qii_DIR . DS . 'Response'],
-        ['Qii\Router', Qii_DIR . DS . 'Router'],
-        ['Qii\View', Qii_DIR . DS . 'View'],
-        ['Smarty', Qii_DIR . DS . 'View' . DS . 'smarty'],
-        ['Smarty', Qii_DIR . DS . 'View' . DS . 'smarty' . DS . 'sysplugins'],
-        ['WhichBrowser', Qii_DIR . DS . 'Library'. DS . 'Third'. DS . 'WhichBrowser'],
-        ['BigPipe', Qii_DIR . DS . 'Library'. DS .'BigPipe'. DS .'BigPipe']
-    ]
-];
+    'addNamespace' => array(
+        array('Qii\\', Qii_DIR . DS),
+        array('Qii\Action', Qii_DIR . DS . 'Action'),
+        array('Qii\Autoloader', Qii_DIR . DS . 'Autoloader'),
+        array('Qii\Controller', Qii_DIR . DS . 'Controller'),
+        array('Qii\Bootstrap', Qii_DIR . DS . 'Bootstrap'),
+        array('Qii\Config', Qii_DIR . DS . 'Config'),
+        array('Qii\Consts', Qii_DIR . DS . 'Consts'),
+        array('Qii\Exceptions', Qii_DIR . DS . 'Exceptions'),
+        array('Qii\Language', Qii_DIR . DS . 'Language'),
+        array('Qii\Library', Qii_DIR . DS . 'Library'),
+        array('Qii\Logger', Qii_DIR . DS . 'Logger'),
+        array('Qii\Plugin', Qii_DIR . DS . 'Plugin'),
+        array('Qii\Request', Qii_DIR . DS . 'Request'),
+        array('Qii\Response', Qii_DIR . DS . 'Response'),
+        array('Qii\Router', Qii_DIR . DS . 'Router'),
+        array('Qii\View', Qii_DIR . DS . 'View'),
+        array('Smarty', Qii_DIR . DS . 'View' . DS . 'smarty'),
+        array('Smarty', Qii_DIR . DS . 'View' . DS . 'smarty' . DS . 'sysplugins'),
+        array('WhichBrowser', Qii_DIR . DS . 'Library'. DS . 'Third'. DS . 'WhichBrowser'),
+        array('BigPipe', Qii_DIR . DS . 'Library'. DS .'BigPipe'. DS .'BigPipe')
+    ),
+);

+ 1 - 1
src/Config/Mine.php

@@ -220,7 +220,7 @@ class Mine
      * 通过 $this->get{对应的文件类型} 来获取mineType,或者getAll获取所有的
      *
      * @param $name
-     * @return array|mixed|string
+     * @return array|string
      */
     public function __get($name)
     {

+ 4 - 4
src/Config/Register.php

@@ -39,9 +39,9 @@ class Register
 	/**
 	 * 设置键值
 	 *
-	 * @param String $key
-	 * @param String $val
-	 * @param Bool overwrite 是否覆盖之前保存的值,如果之前保存了值,要想再保存需要额外设置它为true,否则不让保存
+	 * @param string $key
+	 * @param array|string $val
+	 * @param bool overwrite 是否覆盖之前保存的值,如果之前保存了值,要想再保存需要额外设置它为true,否则不让保存
 	 */
 	public static function set($key, $val, $overwrite = true)
 	{
@@ -329,7 +329,7 @@ class Register
 	/**
 	 * 获取网站的配置信息
 	 *
-	 * @return Array
+	 * @return array
 	 */
 	public static function getAppConfigure($iniFile = Consts::APP_INI, $key = NULL)
 	{

+ 1 - 1
src/Config/Setting.php

@@ -35,7 +35,7 @@ class Setting
      * 设置默认语言
      *
      * @return $this
-     * @throws Exception
+     * @throws \Exception
      */
     public function setDefaultLanguage()
     {

+ 16 - 13
src/Driver/Base.php

@@ -1,6 +1,9 @@
 <?php
-
 namespace Qii\Driver;
+
+use Qii\Autoloader\Psr4;
+use Qii\Exceptions\InvalidParams;
+
 /**
  * Class Base
  * @package Qii\Driver
@@ -78,9 +81,9 @@ class Base
 
     public function __construct()
     {
-        $this->language = \Qii\Autoloader\Psr4::getInstance()->loadClass('Qii\Language\Loader');
-        $this->load = \Qii\Autoloader\Psr4::getInstance()->loadClass('\Qii\Autoloader\Loader');
-        $this->response = new \Qii\Driver\Response();
+        $this->language = Psr4::getInstance()->loadClass('Qii\Language\Loader');
+        $this->load = Psr4::getInstance()->loadClass('\Qii\Autoloader\Loader');
+        $this->response = new Response();
     }
     /**
      * 获取所有数据
@@ -145,7 +148,7 @@ class Base
     final function insertObject($table, $dataArray)
     {
         if (empty($table)) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', 'table'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', 'table'), __LINE__);
         }
         $replaceObj = $this->createInsertReplaceObj($dataArray);
         if(empty($replaceObj['fields']) || empty($replaceObj['values']))
@@ -166,7 +169,7 @@ class Base
     final function replaceObject($table, $dataArray)
     {
         if (empty($table)) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', 'table'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', 'table'), __LINE__);
         }
         $replaceObj = $this->createInsertReplaceObj($dataArray);
         if(empty($replaceObj['fields']) || empty($replaceObj['values']))
@@ -212,7 +215,7 @@ class Base
     public function update($table)
     {
         if(!$table) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', '表名'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', '表名'), __LINE__);
         }
         $set = join(",", $this->sets);
         $this->sets = array();
@@ -238,7 +241,7 @@ class Base
      */
     final function updateObject($table, $dataArray, $where = array()){
         if(!$table) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', '表名'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', '表名'), __LINE__);
         }
         return $this->set($dataArray)->where($where)->update($table);
     }
@@ -274,7 +277,7 @@ class Base
     final function deleteObject($table, $where = null)
     {
         if(!$table) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', '表名'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', '表名'), __LINE__);
         }
         return $this->where($where)->delete($table);
     }
@@ -309,7 +312,7 @@ class Base
     {
         $this->limit = null;
         if($limit === '' || $limit === null) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', 'Limit'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', 'Limit'), __LINE__);
         }
         if ($limit !== '') {
             if (!$offset) {
@@ -612,7 +615,7 @@ class Base
         {
             if(!in_array(strtolower($sort), $allowSortOff) && $countOrder == $i)
             {
-                throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', 'sort'), __LINE__);
+                throw new InvalidParams(_i('%s is invalid', 'sort'), __LINE__);
             }
             $alias = $this->getFieldAlias($key);
 
@@ -756,7 +759,7 @@ class Base
     public function createSelectSQL($table)
     {
         if(!$table) {
-            throw new \Qii\Exceptions\InvalidParams(_i('%s is invalid', '表名'), __LINE__);
+            throw new InvalidParams(_i('%s is invalid', '表名'), __LINE__);
 
         }
         $aliases = $this->getTableAlias($table);
@@ -985,7 +988,7 @@ class Base
             //如果上一次是操作符,这次又是操作符,就是用当前的操作符,去掉上一个操作符
             if($lastIsOperator && $isOperator)
             {
-                if(!$this->faultTolerant) throw new \Qii\Exceptions\InvalidParams(_i('Unsupported operator'), __LINE__);
+                if(!$this->faultTolerant) throw new InvalidParams(_i('Unsupported operator'), __LINE__);
                 array_pop($where);
                 $where[] = $val;
                 continue;

+ 5 - 2
src/Driver/ConnBase.php

@@ -10,10 +10,13 @@ class ConnBase
 {
 	const VERSION = '1.2';
 	/**
-	 * @var $allowExec  读写对应的数据库配置文件
+	 * @var array $allowExec  读写对应的数据库配置文件
 	 */
 	public $allowExec = array("WRITE" => 'master', 'READ' => 'slave');
-
+    /**
+     * @var array $_dbInfo 数据库配置信息
+     */
+    protected $_dbInfo;
 	/**
 	 * 获取数据库配置中指定的key的值,不指定则获取全部
 	 * @param string key 数据库配置中指定的key

+ 7 - 3
src/Driver/Easy.php

@@ -39,7 +39,11 @@
  */
 namespace Qii\Driver;
 
-\Qii\Autoloader\Import::requires(dirname(__FILE__) . DS . 'Response.php');
+use Qii\Autoloader\Import;
+use Qii\Autoloader\Psr4;
+use Qii\Exceptions\TableException;
+
+Import::requires(dirname(__FILE__) . DS . 'Response.php');
 
 class Easy
 {
@@ -85,7 +89,7 @@ class Easy
 
 	public function __construct()
 	{
-		$this->db = \Qii\Autoloader\Psr4::getInstance()->loadClass('\Qii\Driver\Model')->db;
+		$this->db = Psr4::getInstance()->loadClass('\Qii\Driver\Model')->db;
 		$this->clean();
 		return $this;
 	}
@@ -208,7 +212,7 @@ class Easy
 	{
 		if (!$this->isInstance) {
 			$this->_response = Response::Fail('checkInstance', array('msg' => \Qii::i(1507, 'parent::__construct()'), 'code' => __LINE__));
-			throw new \Qii\Exceptions\TableException(\Qii::i(1507, 'parent::__construct()'), __LINE__);
+			throw new TableException(\Qii::i(1507, 'parent::__construct()'), __LINE__);
 		}
 		return $this;
 	}

+ 3 - 1
src/Driver/Fields.php

@@ -8,6 +8,8 @@
  */
 namespace Qii\Driver;
 
+use Qii\Exceptions\MethodNotFound;
+
 final class Fields
 {
 	const VERSION = '1.2';
@@ -87,6 +89,6 @@ final class Fields
 
 	public function __call($method, $argvs)
 	{
-		throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $method . ' Not found'), __LINE__);
+		throw new MethodNotFound(\Qii::i(1101, $method . ' Not found'), __LINE__);
 	}
 }

+ 1 - 1
src/Driver/Intf.php

@@ -7,7 +7,7 @@ namespace Qii\Driver;
 
 interface Intf
 {
-	public function __construct(\Qii\Driver\ConnIntf $connection);
+	public function __construct(ConnIntf $connection);
 
 	/**
 	 * 执行SQL前检查是读/写

+ 17 - 12
src/Driver/Model.php

@@ -22,11 +22,16 @@
  */
 namespace Qii\Driver;
 
+use Qii\Autoloader\Import;
+use Qii\Autoloader\Psr4;
+use Qii\Config\Consts;
+use Qii\Config\Register;
+
 class Model
 {
     const VERSION = '1.2';
     /**
-     * @var $_allow 允许使用的数据库驱动类新
+     * @var array $_allow 允许使用的数据库驱动类新
      */
     protected $_allow = array('pdo', 'mysql', 'mysqli');
     /**
@@ -55,11 +60,11 @@ class Model
      */
     private $rules = null;
     /**
-     * @var \Qii_Driver_Easy $model
+     * @var \Qii\Driver\Easy $model
      */
     private $model = array();
     /**
-     * @var Qii_Request_Abstract $_request 请求类
+     * @var \Qii\Request\Abstract $_request 请求类
      */
     protected $_request;
     /**
@@ -69,27 +74,27 @@ class Model
 
     public function __construct()
     {
-        $this->_load = \Qii\Autoloader\Psr4::getInstance()->loadClass('\Qii\Autoloader\Loader');
-        $this->_language = \Qii\Autoloader\Psr4::getInstance()->loadClass('\Qii\Language\Loader');
-        $this->_request = \Qii\Autoloader\Psr4::getInstance()->loadClass('Qii\Request\Http');
-        $this->_helper = \Qii\Autoloader\Psr4::getInstance()->loadClass('Qii\Autoloader\Helper');
-        $this->_dbInfo = \Qii\Config\Register::getAppConfigure(\Qii\Config\Register::get(\Qii\Config\Consts::APP_DB));
+        $this->_load = Psr4::getInstance()->loadClass('\Qii\Autoloader\Loader');
+        $this->_language = Psr4::getInstance()->loadClass('\Qii\Language\Loader');
+        $this->_request = Psr4::getInstance()->loadClass('Qii\Request\Http');
+        $this->_helper = Psr4::getInstance()->loadClass('Qii\Autoloader\Helper');
+        $this->_dbInfo = Register::getAppConfigure(Register::get(Consts::APP_DB));
         if (isset($this->_dbInfo['driver'])) {
             $this->_driver = $this->_dbInfo['driver'];
         }
         if (!in_array($this->_driver, $this->_allow)) {
             $this->_driver = array_shift($this->_allow);
         }
-        \Qii\Autoloader\Import::requires(array(
+        Import::requires(array(
             Qii_DIR . DS . 'Qii' . DS . 'Driver' . DS . 'Base.php',
             Qii_DIR . DS . 'Qii' . DS . 'Driver' . DS . 'ConnBase.php',
             Qii_DIR . DS . 'Qii' . DS . 'Driver' . DS . 'ConnIntf.php',
             Qii_DIR . DS . 'Qii' . DS . 'Driver' . DS . ucWords($this->_driver) . DS . 'Connection.php',
             Qii_DIR . DS . 'Qii' . DS . 'Driver' . DS . ucWords($this->_driver) . DS . 'Driver.php',
         ));
-        $this->db = \Qii\Autoloader\Psr4::getInstance()->loadClass(
+        $this->db = Psr4::getInstance()->loadClass(
             '\Qii\Driver\\' . ucWords($this->_driver) . '\Driver',
-            \Qii\Autoloader\Psr4::getInstance()->loadClass(
+            Psr4::getInstance()->loadClass(
                 '\Qii\Driver\\' . ucWords($this->_driver) . '\Connection'
             )
         );
@@ -215,7 +220,7 @@ class Model
     /**
      * 删除数据
      * @param array $fields 数据
-     * @return \Qii_Response
+     * @return \Qii\Response
      */
     final public function _remove($fields, $privateKey = array())
     {

+ 1 - 1
src/Driver/Observer.php

@@ -46,7 +46,7 @@ class Observer implements SplSubject
 
 	/**
 	 * Observer constructor.
-	 * @param $context 调用此方法的类
+	 * @param object $context 调用此方法的类
 	 */
 	public function __construct($context)
 	{

+ 12 - 10
src/Driver/Response.php

@@ -78,6 +78,8 @@
  */
 namespace Qii\Driver;
 
+use Qii\Exceptions\MethodNotFound;
+
 class Response
 {
 	const VERSION = '1.2';
@@ -172,7 +174,7 @@ class Response
 	 * 记录不存在
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function NotExist($operate, $result)
 	{
@@ -183,7 +185,7 @@ class Response
 	 * 验证失败
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function FailValidate($operate, $result)
 	{
@@ -194,7 +196,7 @@ class Response
 	 * 保存失败
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function FailSave($operate, $result)
 	{
@@ -205,7 +207,7 @@ class Response
 	 * 更新失败
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function FailUpdate($operate, $result)
 	{
@@ -216,7 +218,7 @@ class Response
 	 * 删除失败
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function FailRemove($operate, $result)
 	{
@@ -227,7 +229,7 @@ class Response
 	 * 方法未定义
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function UndefinedMethod($operate, $result)
 	{
@@ -238,7 +240,7 @@ class Response
 	 * 类失败
 	 * @param string $operate 操作类型
 	 * @param mix $result 结果
-	 * @return Qii\Driver\Response
+	 * @return Response
 	 */
 	public static function UndefinedClass($operate, $result)
 	{
@@ -246,12 +248,12 @@ class Response
 	}
 
 	/**
-	 * 直接初始化Qii\Driver\Response 对象
+	 * 直接初始化Response对象
 	 */
 	public static function Instance($code, $operate, $result)
 	{
 		$data = array('code' => $code, 'body' => array('operate' => $operate, 'result' => $result));
-		return (new \Qii\Driver\Response())->set($data);
+		return (new Response())->set($data);
 	}
 
 	/**
@@ -327,6 +329,6 @@ class Response
 			$propertty = strtolower(substr($method, 3));
 			if (property_exists($this, $propertty)) return $this->$propertty;
 		}
-		throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $method), __LINE__);
+		throw new MethodNotFound(\Qii::i(1101, $method), __LINE__);
 	}
 }

+ 6 - 3
src/Driver/Rules.php

@@ -5,6 +5,9 @@
  */
 namespace Qii\Driver;
 
+use Qii\Exceptions\MethodNotFound;
+use Qii\Exceptions\NotAllowed;
+
 class Rules
 {
 	const VERSION = '1.2';
@@ -188,7 +191,7 @@ class Rules
 		$rules = array();
 		$allowOpt = array('save', 'update', 'remove');
 		if (!in_array($opt, $allowOpt)) {
-			throw new \Qii\Exceptions\NotAllowed(\Qii::i(5002, $opt), __LINE__);
+			throw new NotAllowed(\Qii::i(5002, $opt), __LINE__);
 		}
 		if (isset(self::$cacheRules[$this->rules['database'] . $this->rules['tableName']][$opt])) return self::$cacheRules[$this->rules['database'] . $this->rules['tableName']][$opt];
 		$buildRules = $this->buildRules();
@@ -217,7 +220,7 @@ class Rules
 		if (method_exists($this, $name)) {
 			return call_user_func_array(array($this, $name), array());
 		}
-		throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $name), __LINE__);
+		throw new MethodNotFound(\Qii::i(1101, $name), __LINE__);
 	}
 
 	/**
@@ -227,6 +230,6 @@ class Rules
 	 */
 	public function __call($method, $args)
 	{
-		throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $method), __LINE__);
+		throw new MethodNotFound(\Qii::i(1101, $method), __LINE__);
 	}
 }

+ 5 - 2
src/Driver/TraitCache.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Driver;
 
+use Qii\Autoloader\Import;
+use Qii\Autoloader\Psr4;
+
 trait TraitCache
 {
     public $cache;
@@ -12,8 +15,8 @@ trait TraitCache
      */
     final public function setCache($cache, $policy)
     {
-        \Qii\Autoloader\Import::requires(Qii_DIR . DS . 'Qii' . DS . 'Cache.php');
-        $this->cache = \Qii\Autoloader\Psr4::loadClass('\Qii\Cache', $cache)->initialization($policy);//载入cache类文件
+        Import::requires(Qii_DIR . DS . 'Qii' . DS . 'Cache.php');
+        $this->cache = Psr4::loadClass('\Qii\Cache', $cache)->initialization($policy);//载入cache类文件
     }
 
     /**

+ 1 - 3
src/Driver/TraitDatabase.php

@@ -169,7 +169,6 @@ trait TraitDatabase
         $sql = "SHOW TABLES LIKE '" . $tableName . "'";
         $rs = $this->setQuery($sql);
 
-        $tables = array();
         while ($row = $this->fetch($rs)) {
             if (is_array($row)) {
                 foreach ($row AS $val) {
@@ -247,7 +246,6 @@ trait TraitDatabase
             $tableName = stristr($tableName, '`') || stristr($tableName, " ") ? $tableName : '`'. $tableName .'`';
             return "`{$database}`.`{$tableName}`";
         }
-        $table = stristr($table, '`') || stristr($tableName, " ")  ? $table : '`'. $table .'`';
-        return $table;
+        return stristr($table, '`') || stristr($tableName, " ")  ? $table : '`'. $table .'`';
     }
 }

+ 14 - 9
src/Functions/Funcs.php

@@ -1,4 +1,9 @@
 <?php
+use Qii\Autoloader\Import;
+use Qii\Autoloader\Psr4;
+use Qii\Config\Register;
+use Qii\Language\Loader;
+
 /**
  * Qii ...
  * @return null|Qii|Qii\Autoloader\Psr4
@@ -29,7 +34,7 @@ function _e()
  * @return mixed
  */
 function _log() {
-    return call_user_func_array('\Qii\Library\Chrome::log', func_get_args());
+    return call_user_func_array('\Qii\Logger\Chromelog::log', func_get_args());
 }
 /**
  * 加载语言包
@@ -37,22 +42,22 @@ function _log() {
  */
 function _language($language)
 {
-	\Qii\Language\Loader::getInstance()->load($language);
+	Loader::getInstance()->load($language);
 }
 
 /**
  * \Qii_Config_Register:: get or set
  * @param $key
  * @param null $val
- * @return Mix|void
+ * @return void
  */
 function _config($key, $val = null)
 {
 	if($val === null)
 	{
-		return \Qii\Config\Register::get($key);
+		return Register::get($key);
 	}
-	return \Qii\Config\Register::set($key, $val);
+	return Register::set($key, $val);
 }
 /**
  * Adds a base directory for a namespace prefix.
@@ -76,9 +81,9 @@ function _loader($class = null)
 {
 	$args = func_get_args();
 	if($class != null){
-		return call_user_func_array(array(\Qii\Autoloader\Psr4::getInstance(), 'loadClass'), $args);
+		return call_user_func_array(array(Psr4::getInstance(), 'loadClass'), $args);
 	}
-	return \Qii\Autoloader\Psr4::getInstance();
+	return Psr4::getInstance();
 }
 /**
  * 简便的loadClass方法
@@ -120,12 +125,12 @@ function _DBDriver(\Qii\Driver\Rules $rule, $privateKey = null, $fieldsVal = nul
  * _include include文件
  */
 function _include($files){
-	return \Qii\Autoloader\Import::includes($files);
+	return Import::includes($files);
 }
 
 function _require($files)
 {
-	return \Qii\Autoloader\Import::requires($files);
+	return Import::requires($files);
 }
 
 /**

+ 0 - 448
src/Library/Chrome.php

@@ -1,448 +0,0 @@
-<?php
-/**
- * Copyright 2010-2013 Craig Campbell
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Server Side Chrome PHP debugger class
- *
- * @package ChromePhp
- * @author Craig Campbell <iamcraigcampbell@gmail.com>
- */
-namespace Qii\Library;
-
-class Chrome
-{
-    /**
-     * @var string
-     */
-    const VERSION = '4.1.0';
-
-    /**
-     * @var string
-     */
-    const HEADER_NAME = 'X-ChromeLogger-Data';
-
-    /**
-     * @var string
-     */
-    const BACKTRACE_LEVEL = 'backtrace_level';
-
-    /**
-     * @var string
-     */
-    const LOG = 'log';
-
-    /**
-     * @var string
-     */
-    const WARN = 'warn';
-
-    /**
-     * @var string
-     */
-    const ERROR = 'error';
-
-    /**
-     * @var string
-     */
-    const GROUP = 'group';
-
-    /**
-     * @var string
-     */
-    const INFO = 'info';
-
-    /**
-     * @var string
-     */
-    const GROUP_END = 'groupEnd';
-
-    /**
-     * @var string
-     */
-    const GROUP_COLLAPSED = 'groupCollapsed';
-
-    /**
-     * @var string
-     */
-    const TABLE = 'table';
-
-    /**
-     * @var string
-     */
-    protected $_php_version;
-
-    /**
-     * @var int
-     */
-    protected $_timestamp;
-
-    /**
-     * @var array
-     */
-    protected $_json = array(
-        'version' => self::VERSION,
-        'columns' => array('log', 'backtrace', 'type'),
-        'rows' => array()
-    );
-
-    /**
-     * @var array
-     */
-    protected $_backtraces = array();
-
-    /**
-     * @var bool
-     */
-    protected $_error_triggered = false;
-
-    /**
-     * @var array
-     */
-    protected $_settings = array(
-        self::BACKTRACE_LEVEL => 1
-    );
-
-    /**
-     * @var ChromePhp
-     */
-    protected static $_instance;
-
-    /**
-     * Prevent recursion when working with objects referring to each other
-     *
-     * @var array
-     */
-    protected $_processed = array();
-
-    /**
-     * constructor
-     */
-    private function __construct()
-    {
-        $this->_php_version = phpversion();
-        $this->_timestamp = $this->_php_version >= 5.1 ? $_SERVER['REQUEST_TIME'] : time();
-        $this->_json['request_uri'] = $_SERVER['REQUEST_URI'];
-    }
-
-    /**
-     * gets instance of this class
-     *
-     * @return ChromePhp
-     */
-    public static function getInstance()
-    {
-        if (self::$_instance === null) {
-            self::$_instance = new self();
-        }
-        return self::$_instance;
-    }
-
-    /**
-     * logs a variable to the console
-     *
-     * @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
-     * @return void
-     */
-    public static function log()
-    {
-        $args = func_get_args();
-        return self::_log('', $args);
-    }
-
-    /**
-     * logs a warning to the console
-     *
-     * @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
-     * @return void
-     */
-    public static function warn()
-    {
-        $args = func_get_args();
-        return self::_log(self::WARN, $args);
-    }
-
-    /**
-     * logs an error to the console
-     *
-     * @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
-     * @return void
-     */
-    public static function error()
-    {
-        $args = func_get_args();
-        return self::_log(self::ERROR, $args);
-    }
-
-    /**
-     * sends a group log
-     *
-     * @param string value
-     */
-    public static function group()
-    {
-        $args = func_get_args();
-        return self::_log(self::GROUP, $args);
-    }
-
-    /**
-     * sends an info log
-     *
-     * @param mixed $data,... unlimited OPTIONAL number of additional logs [...]
-     * @return void
-     */
-    public static function info()
-    {
-        $args = func_get_args();
-        return self::_log(self::INFO, $args);
-    }
-
-    /**
-     * sends a collapsed group log
-     *
-     * @param string value
-     */
-    public static function groupCollapsed()
-    {
-        $args = func_get_args();
-        return self::_log(self::GROUP_COLLAPSED, $args);
-    }
-
-    /**
-     * ends a group log
-     *
-     * @param string value
-     */
-    public static function groupEnd()
-    {
-        $args = func_get_args();
-        return self::_log(self::GROUP_END, $args);
-    }
-
-    /**
-     * sends a table log
-     *
-     * @param string value
-     */
-    public static function table()
-    {
-        $args = func_get_args();
-        return self::_log(self::TABLE, $args);
-    }
-
-    /**
-     * internal logging call
-     *
-     * @param string $type
-     * @return void
-     */
-    protected static function _log($type, array $args)
-    {
-        // nothing passed in, don't do anything
-        if (count($args) == 0 && $type != self::GROUP_END) {
-            return;
-        }
-
-        $logger = self::getInstance();
-
-        $logger->_processed = array();
-
-        $logs = array();
-        foreach ($args as $arg) {
-            $logs[] = $logger->_convert($arg);
-        }
-
-        $backtrace = debug_backtrace(false);
-        $level = $logger->getSetting(self::BACKTRACE_LEVEL);
-
-        $backtrace_message = 'unknown';
-        if (isset($backtrace[$level]['file']) && isset($backtrace[$level]['line'])) {
-            $backtrace_message = $backtrace[$level]['file'] . ' : ' . $backtrace[$level]['line'];
-        }
-
-        $logger->_addRow($logs, $backtrace_message, $type);
-    }
-
-    /**
-     * converts an object to a better format for logging
-     *
-     * @param Object
-     * @return array
-     */
-    protected function _convert($object)
-    {
-        // if this isn't an object then just return it
-        if (!is_object($object)) {
-            return $object;
-        }
-
-        //Mark this object as processed so we don't convert it twice and it
-        //Also avoid recursion when objects refer to each other
-        $this->_processed[] = $object;
-
-        $object_as_array = array();
-
-        // first add the class name
-        $object_as_array['___class_name'] = get_class($object);
-
-        // loop through object vars
-        $object_vars = get_object_vars($object);
-        foreach ($object_vars as $key => $value) {
-
-            // same instance as parent object
-            if ($value === $object || in_array($value, $this->_processed, true)) {
-                $value = 'recursion - parent object [' . get_class($value) . ']';
-            }
-            $object_as_array[$key] = $this->_convert($value);
-        }
-
-        $reflection = new ReflectionClass($object);
-
-        // loop through the properties and add those
-        foreach ($reflection->getProperties() as $property) {
-
-            // if one of these properties was already added above then ignore it
-            if (array_key_exists($property->getName(), $object_vars)) {
-                continue;
-            }
-            $type = $this->_getPropertyKey($property);
-
-            if ($this->_php_version >= 5.3) {
-                $property->setAccessible(true);
-            }
-
-            try {
-                $value = $property->getValue($object);
-            } catch (ReflectionException $e) {
-                $value = 'only PHP 5.3 can access private/protected properties';
-            }
-
-            // same instance as parent object
-            if ($value === $object || in_array($value, $this->_processed, true)) {
-                $value = 'recursion - parent object [' . get_class($value) . ']';
-            }
-
-            $object_as_array[$type] = $this->_convert($value);
-        }
-        return $object_as_array;
-    }
-
-    /**
-     * takes a reflection property and returns a nicely formatted key of the property name
-     *
-     * @param ReflectionProperty
-     * @return string
-     */
-    protected function _getPropertyKey(ReflectionProperty $property)
-    {
-        $static = $property->isStatic() ? ' static' : '';
-        if ($property->isPublic()) {
-            return 'public' . $static . ' ' . $property->getName();
-        }
-
-        if ($property->isProtected()) {
-            return 'protected' . $static . ' ' . $property->getName();
-        }
-
-        if ($property->isPrivate()) {
-            return 'private' . $static . ' ' . $property->getName();
-        }
-    }
-
-    /**
-     * adds a value to the data array
-     *
-     * @var mixed
-     * @return void
-     */
-    protected function _addRow(array $logs, $backtrace, $type)
-    {
-        // if this is logged on the same line for example in a loop, set it to null to save space
-        if (in_array($backtrace, $this->_backtraces)) {
-            $backtrace = null;
-        }
-
-        // for group, groupEnd, and groupCollapsed
-        // take out the backtrace since it is not useful
-        if ($type == self::GROUP || $type == self::GROUP_END || $type == self::GROUP_COLLAPSED) {
-            $backtrace = null;
-        }
-
-        if ($backtrace !== null) {
-            $this->_backtraces[] = $backtrace;
-        }
-
-        $row = array($logs, $backtrace, $type);
-
-        $this->_json['rows'][] = $row;
-        $this->_writeHeader($this->_json);
-    }
-
-    protected function _writeHeader($data)
-    {
-        header(self::HEADER_NAME . ': ' . $this->_encode($data));
-    }
-
-    /**
-     * encodes the data to be sent along with the request
-     *
-     * @param array $data
-     * @return string
-     */
-    protected function _encode($data)
-    {
-        return base64_encode(utf8_encode(json_encode($data)));
-    }
-
-    /**
-     * adds a setting
-     *
-     * @param string key
-     * @param mixed value
-     * @return void
-     */
-    public function addSetting($key, $value)
-    {
-        $this->_settings[$key] = $value;
-    }
-
-    /**
-     * add ability to set multiple settings in one call
-     *
-     * @param array $settings
-     * @return void
-     */
-    public function addSettings(array $settings)
-    {
-        foreach ($settings as $key => $value) {
-            $this->addSetting($key, $value);
-        }
-    }
-
-    /**
-     * gets a setting
-     *
-     * @param string key
-     * @return mixed
-     */
-    public function getSetting($key)
-    {
-        if (!isset($this->_settings[$key])) {
-            return null;
-        }
-        return $this->_settings[$key];
-    }
-}

+ 6 - 7
src/Logger/Instance.php

@@ -4,14 +4,13 @@
  */
 namespace Qii\Logger;
 
-use \Qii\Logger\Writer;
 class Instance
 {
 	const VERSION = '1.2';
 	/**
 	 * loger writer
 	 */
-	private $logerHooker;
+	private $loggerHooker;
 
 	public function __construct(Writer $hooker)
 	{
@@ -23,7 +22,7 @@ class Instance
 	 */
 	public function setHooker(Writer $hooker)
 	{
-		$this->logerHooker = $hooker;
+		$this->loggerHooker = $hooker;
 	}
 
 	/**
@@ -31,8 +30,8 @@ class Instance
 	 */
 	public function setFileName($fileName)
 	{
-		if (method_exists($this->logerHooker, 'setFilename')) {
-			$this->logerHooker->setFilename($fileName);
+		if (method_exists($this->loggerHooker, 'setFilename')) {
+			$this->loggerHooker->setFilename($fileName);
 		}
 	}
 
@@ -41,8 +40,8 @@ class Instance
 	 */
 	public function writeLog($loger)
 	{
-		if (method_exists($this->logerHooker, 'writeLog')) {
-			$this->logerHooker->writeLog($loger);
+		if (method_exists($this->loggerHooker, 'writeLog')) {
+			$this->loggerHooker->writeLog($loger);
 		}
 	}
 }

+ 1 - 1
src/Logger/Writer.php

@@ -4,5 +4,5 @@ namespace Qii\Logger;
 interface Writer
 {
 	public function setFileName($fileName);
-	public function writeLog($loger);
+	public function writeLog($logger);
 }

+ 1 - 1
src/Plugin/Intf.php

@@ -3,5 +3,5 @@ namespace Qii\Plugin;
 
 interface Intf
 {
-    public function __construct(\Qii\Plugin\Plugin &$pluginManger);
+    public function __construct(Plugin &$pluginManger);
 }

+ 3 - 3
src/Plugin/Plugin.php

@@ -64,9 +64,9 @@ class Plugin
 
     /**
      * 注册插件
-     * @param $hook 钩子名称
-     * @param $reference 插件的引用
-     * @param $method 钩子对应的方法名
+     * @param string $hook 钩子名称
+     * @param string $reference 插件的引用
+     * @param string $method 钩子对应的方法名
      */
     public function register($hook, &$reference, $method)
     {

+ 19 - 21
src/Qii.php

@@ -1,4 +1,9 @@
 <?php
+use \Qii\Application;
+use \Qii\Autoloader\Factory;
+use Qii\Autoloader\Import;
+use \Qii\Autoloader\Psr4;
+use \Qii\Config\Register;
 /**
  * Qii 框架基本库所在路径
  */
@@ -6,17 +11,18 @@ define('Qii_DIR', dirname(__FILE__));
 /**
  * DIRECTORY_SEPARATOR 的简写
  */
-define('DS', DIRECTORY_SEPARATOR);
+const DS = DIRECTORY_SEPARATOR;
 /**
  * 定义包含的路径分隔符
  */
-define('PS', PATH_SEPARATOR);
+const PS = PATH_SEPARATOR;
 /**
  * 定义操作系统类型
  */
 define('OS', strtoupper(substr(PHP_OS, 0, 3)));
 
-define('IS_CLI', php_sapi_name() == 'cli' ? true : false);
+define('IS_CLI', php_sapi_name() == 'cli');
+
 if (IS_CLI) {
     define('PATH_INFO', array_pop($argv));
 } else {
@@ -30,9 +36,9 @@ define('QII_EOL', IS_CLI ? PHP_EOL : '<br />');
 define('QII_SPACE', IS_CLI ? ' ' : '&nbsp;');
 
 require Qii_DIR . DS . 'Autoloader' . DS . 'Import.php';
-\Qii\Autoloader\Import::setFileLoaded(Qii_DIR . DS . 'Autoloader' . DS . 'Import.php');
+Import::setFileLoaded(Qii_DIR . DS . 'Autoloader' . DS . 'Import.php');
 
-\Qii\Autoloader\Import::requires(
+Import::requires(
     array(Qii_DIR . DS . 'Config' . DS . 'Consts.php',
         Qii_DIR . DS . 'Functions' . DS . 'Funcs.php',
         Qii_DIR . DS . 'Autoloader' . DS . 'Factory.php',
@@ -42,13 +48,6 @@ require Qii_DIR . DS . 'Autoloader' . DS . 'Import.php';
     )
 );
 
-use \Qii\Application;
-
-use \Qii\Autoloader\Factory;
-use \Qii\Autoloader\Psr4;
-
-use \Qii\Config\Register;
-
 class Qii extends Application
 {
     public function __construct()
@@ -115,8 +114,7 @@ class Qii extends Application
      *
      * @param Bool $condition
      * @param int $line 出错的行数,这样以便轻松定位错误
-     * @param String $msg
-     * @param Int|String $code
+     * @param int|String $code
      * @return Bool
      */
     public static function setError($condition, $line = 0, $code, $args = null)
@@ -137,7 +135,7 @@ class Qii extends Application
     /**
      * 返回当前app的配置
      * @param string $key 如果需要返回单独的某一个key就指定一下这个值
-     * @return Mix
+     * @return array
      */
     public static function appConfigure($key = null)
     {
@@ -197,15 +195,15 @@ if (!function_exists('catch_fatal_error')) {
 
 //注册名称空间
 $namespace = _include(Qii_DIR . DS . 'Conf' . DS . 'namespace.php');
-\Qii\Autoloader\Psr4::getInstance()
+Psr4::getInstance()
     ->register()
-    ->setUseNamespaces($namespace['setUseNamespace'] ?? [])
-    ->addNamespaces($namespace['addNamespace'] ?? []);
+    ->setUseNamespaces(isset($namespace['setUseNamespace']) && is_array($namespace['setUseNamespace']) ? $namespace['setUseNamespace'] : [])
+    ->addNamespaces(isset($namespace['addNamespace']) && is_array($namespace['addNamespace']) ? $namespace['addNamespace'] : []);
 
 //加载默认语言包
-\Qii\Autoloader\Factory::getInstance('\Qii\Language\Loader')->load('error', Qii_DIR . DS . 'Language');
-\Qii\Autoloader\Factory::getInstance('\Qii\Language\Loader')->load('exception', Qii_DIR . DS . 'Language');
-\Qii\Autoloader\Factory::getInstance('\Qii\Language\Loader')->load('resource', Qii_DIR . DS . 'Language');
+Factory::getInstance('\Qii\Language\Loader')->load('error', Qii_DIR . DS . 'Language');
+Factory::getInstance('\Qii\Language\Loader')->load('exception', Qii_DIR . DS . 'Language');
+Factory::getInstance('\Qii\Language\Loader')->load('resource', Qii_DIR . DS . 'Language');
 
 
 //捕获FATAL错误,用户可以选择记录到日志,还是直接显示或者不显示错误

+ 13 - 8
src/Request/Http.php

@@ -33,10 +33,11 @@ final class Http extends Request
                     }
 
                     /* IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem) */
-                    if ($rewrited = (boolean)$this->getServer('IIS_WasUrlRewritten')) {
-                        $unencode = $this->getServer('UNENCODED_URL');
-                        if ($unencode && is_string($unencode)) {
-                            $requestURI = $unencode;
+                    $rewrite = (boolean)$this->getServer('IIS_WasUrlRewritten');
+                    if ($rewrite) {
+                        $unEncode = $this->getServer('UNENCODED_URL');
+                        if ($unEncode && is_string($unEncode)) {
+                            $requestURI = $unEncode;
                         }
                         break;
                     }
@@ -179,13 +180,17 @@ final class Http extends Request
     {
         if (isset($this->params[$name])) {
             return $this->params[$name];
-        } elseif (isset($_POST[$name])) {
+        }
+        if (isset($_POST[$name])) {
             return $_POST[$name];
-        } elseif (isset($_GET[$name])) {
+        }
+        if (isset($_GET[$name])) {
             return $_GET[$name];
-        } elseif (isset($_COOKIE[$name])) {
+        }
+        if (isset($_COOKIE[$name])) {
             return $_COOKIE[$name];
-        } elseif (isset($_SERVER[$name])) {
+        }
+        if (isset($_SERVER[$name])) {
             return $_SERVER[$name];
         }
         return $default;

+ 1 - 1
src/Request/Sample.php

@@ -17,7 +17,7 @@ final class Simple extends Request
 	public function __construct ($module, $controller, $action, $method, $params = null)
 	{
 		if ($params && !is_array($params)) {
-			unset($this);
+			unset($params);
 			trigger_error('Expects the params is an array', E_USER_ERROR);
 			return false;
 		}

+ 9 - 6
src/Request/Url.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Request;
 
+use Qii\Autoloader\Psr4;
+use Qii\Exceptions\Unsupported;
+
 /**
  * 返回URL处理方法
  */
@@ -16,10 +19,10 @@ class Url
     {
         $allow = array('Normal', 'Middle', 'Short');
         if (!in_array($rewriteRule, $allow)) {
-            throw new \Qii\Exceptions\Unsupported("链接模式错误,链接格式只能为 '<u><font color=\"green\">" . join("', '", $allow) . "</font></u>',当前模式为 '<font color=\"red\">" . $rewriteRule . "</font>'", __LINE__);
+            throw new Unsupported("链接模式错误,链接格式只能为 '<u><font color=\"green\">" . join("', '", $allow) . "</font></u>',当前模式为 '<font color=\"red\">" . $rewriteRule . "</font>'", __LINE__);
         }
         $className = '\Qii\Request\Url\\' . $rewriteRule;
-        $this->request = \Qii\Autoloader\Psr4::getInstance()->loadClass($className, $rewriteRule);
+        $this->request = Psr4::getInstance()->loadClass($className, $rewriteRule);
         return $this;
     }
 
@@ -59,7 +62,7 @@ class Url
     public static function getCurrentURL()
     {
         $rewriteRule = \Qii::getInstance()->appConfigure(\Qii\Config\Consts::APP_SITE_METHOD);
-        return \Qii\Request\Url::getInstance($rewriteRule)->request->getCurrentURL();
+        return Url::getInstance($rewriteRule)->request->getCurrentURL();
     }
 
     /**
@@ -69,7 +72,7 @@ class Url
     public static function getHost()
     {
         $rewriteRule = \Qii::getInstance()->appConfigure(\Qii\Config\Consts::APP_SITE_METHOD);
-        return \Qii\Request\Url::getInstance($rewriteRule)->request->getWebHost();
+        return Url::getInstance($rewriteRule)->request->getWebHost();
     }
 
     /**
@@ -79,7 +82,7 @@ class Url
     public static function getSubdomain()
     {
         $rewriteRule = \Qii::getInstance()->appConfigure(\Qii\Config\Consts::APP_SITE_METHOD);
-        $host = \Qii\Request\Url::getInstance($rewriteRule)->request->getWebHost();
+        $host = Url::getInstance($rewriteRule)->request->getWebHost();
         $domain = parse_url($host)['host'] ?? "";
 
         if (stristr($domain, ".")) {
@@ -94,7 +97,7 @@ class Url
     public static function pathUrl()
     {
         $rewriteRule = \Qii::getInstance()->appConfigure(\Qii\Config\Consts::APP_SITE_METHOD);
-        return \Qii\Request\Url::getInstance($rewriteRule)->request->getWebHost() . \Qii::getInstance()->request->url->getPath();
+        return Url::getInstance($rewriteRule)->request->getWebHost() . \Qii::getInstance()->request->url->getPath();
     }
 
     /**

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

@@ -1,6 +1,8 @@
 <?php
 namespace Qii\Request\Url;
 
+use Qii\Exceptions\Unsupported;
+
 abstract class Base
 {
     const VERSION = '1.2';
@@ -408,7 +410,7 @@ abstract class Base
     public function checkMode($mode)
     {
         if (!in_array($mode, $this->_allowMode)) {
-            throw new \Qii\Exceptions\Unsupported("链接模式错误,链接格式只能为 '<u><font color=\"green\">" . join("', '", $this->_allowMode) . "</font></u>',当前模式为 '<font color=\"red\">" . $mode . "</font>'", __LINE__);
+            throw new Unsupported("链接模式错误,链接格式只能为 '<u><font color=\"green\">" . join("', '", $this->_allowMode) . "</font></u>',当前模式为 '<font color=\"red\">" . $mode . "</font>'", __LINE__);
         }
     }
     /**

+ 3 - 1
src/Response/Cli.php

@@ -1,7 +1,9 @@
 <?php
 namespace Qii\Response;
 
-class Cli extends \Qii\Base\Response
+use Qii\Base\Response;
+
+class Cli extends Response
 {
     public function __construct($body = null)
     {

+ 3 - 1
src/Response/Http.php

@@ -1,7 +1,9 @@
 <?php
 namespace Qii\Response;
 
-class Http extends \Qii\Base\Response
+use Qii\Base\Response;
+
+class Http extends Response
 {
     protected $_sendheader = true;
     protected $_responseCode = 200;

+ 7 - 5
src/Router/Parse.php

@@ -5,6 +5,7 @@ use \Qii\Autoloader\Import;
 
 use \Qii\Config\Register;
 use \Qii\Config\Consts;
+use Qii\Exceptions\ClassNotFound;
 
 /**
  * 路由规则类
@@ -19,10 +20,11 @@ class Parse
     /**
      * 路由转发, 转发对应的规则中xx不能为*
      *
-     * @param String $controller
-     * @param String $action
-     * @param Array $router
-     * @return Array ($controller, $action);
+     * @param string $url url
+     * @param string $controller controller名
+     * @param string $action action名
+     * @param array $thirdParam 参数
+     * @return array ($controller, $action);
      *
      * *:* => *:yyy 所有controller和action都转发到 *->yyy
      * *:* => yy:* 所有转发到xxx->*, 这里的*,前边对应的是什么,后边就对应转发到什么,比如: *:xxx => yy:yyy
@@ -42,7 +44,7 @@ class Parse
         Import::requires(Qii_DIR . DS . 'Router' . DS . 'Parse' .DS. $rewriteRule . '.php');
         $className = '\Qii\Router\Parse\\' . $rewriteRule;
         if (!class_exists($className, false)) {
-            throw new \Qii\Exceptions\ClassNotFound(\Qii::i(1103, $className), __LINE__);
+            throw new ClassNotFound(\Qii::i(1103, $className), __LINE__);
         }
         $class = new $className();
         $class->setConfig($router);

+ 1 - 1
src/Router/Parse/Normal.php

@@ -183,7 +183,7 @@ class Normal
         }
         list($controller, $action) = explode(":", $rulesVal);
         $match['controller'] = $controller;
-        $match['action'] = $action ?? 'index';
+        $match['action'] = isset($action) && $action != "" ? $action : 'index';
         $match['replacements'] = $replacements;
         $match['rulesVal'] = $rulesVal;
 

+ 1 - 3
src/Router/Parse/Regx.php

@@ -47,6 +47,4 @@ class Regx
 		}
 		return array('controller' => $controller, 'action' => $action);
 	}
-}
-
-?>
+}

+ 4 - 4
src/View/Includes.php

@@ -8,6 +8,8 @@
  */
 namespace Qii\View;
 
+use Qii\Config\Register;
+
 class Includes implements \Qii\View\Intf
 {
 	const VERSION = '1.2';
@@ -17,7 +19,7 @@ class Includes implements \Qii\View\Intf
 
 	public function __construct()
 	{
-		$appConfigure = \Qii\Config\Register::getAppConfigure(\Qii\Config\Register::get(\Qii\Config\Consts::APP_INI_FILE));
+		$appConfigure = Register::getAppConfigure(Register::get(\Qii\Config\Consts::APP_INI_FILE));
 		$this->viewPath = $appConfigure['view']['path'];
 	}
 
@@ -85,6 +87,4 @@ class Includes implements \Qii\View\Intf
 			include($tpl);
 		}
 	}
-}
-
-?>
+}

+ 3 - 1
src/View/Loader.php

@@ -1,6 +1,8 @@
 <?php
 namespace Qii\View;
 
+use Qii\Exceptions\Unsupported;
+
 class Loader
 {
 	protected $view;
@@ -15,7 +17,7 @@ class Loader
 	{
 		if(!in_array($engine, $this->allow))
 		{
-			throw new \Qii\Exceptions\Unsupported(\Qii::i('Unsupported method', $engine));
+			throw new Unsupported(\Qii::i('Unsupported method', $engine));
 		}
 		$class = '\Qii\View\\'. ucwords($engine);
 		return $this->view = new $class();

+ 10 - 8
src/View/Render.php

@@ -1,10 +1,12 @@
 <?php
 namespace Qii\View;
 
+use Qii\Autoloader\Psr4;
+
 class Render
 {
 	protected $_view;
-	public function __construct(&$view, \Qii\View\Resource $resource)
+	public function __construct(&$view, Resource $resource)
 	{
 		$this->_view = $view;
 	}
@@ -13,7 +15,7 @@ class Render
 	 * renderJS
 	 * @param \widget\resource $resource 资源
 	 */
-	public function renderLinkJs(\Qii\View\Resource $resource)
+	public function renderLinkJs(Resource $resource)
 	{
 		$blockJs = array();
 		if (isset(\Qii\View\Dependence::$dependence['blockLinkJs'])) {
@@ -36,7 +38,7 @@ class Render
 	 * renderCss
 	 * @param \widget\resource $resource 资源
 	 */
-	public function renderLinkCss(\Qii\View\Resource $resource)
+	public function renderLinkCss(Resource $resource)
 	{
 		$blockCss = array();
 		if (isset(\Qii\View\Dependence::$dependence['blockLinkCss'])) {
@@ -59,7 +61,7 @@ class Render
 	 * renderJS
 	 * @param \widget\resource $resource 资源
 	 */
-	public function renderJs(\Qii\View\Resource $resource)
+	public function renderJs(Resource $resource)
 	{
 		$blockJs = '';
 		if (isset(\Qii\View\Dependence::$dependence['blockJs'])) {
@@ -83,7 +85,7 @@ class Render
 	 * renderCss
 	 * @param \widget\resource $resource 资源
 	 */
-	public function renderCss(\Qii\View\Resource $resource)
+	public function renderCss(Resource $resource)
 	{
 		$blockCss = '';
 		if (isset(\Qii\View\Dependence::$dependence['blockCss'])) {
@@ -108,7 +110,7 @@ class Render
 	 *
 	 * @param string $tpl 模板名
 	 */
-	public function render(\Qii\View\Resource $resource)
+	public function render(Resource $resource)
 	{
 		$this->_view->assign('pageTitle', $resource->title);
 		$this->_view->assign('bodyClass', $resource->bodyClass);
@@ -129,7 +131,7 @@ class Render
 				continue;
 			}
 			$executed[$className . ':' . $method] = true;
-			$class = \Qii\Autoloader\Psr4::loadClass($className);
+			$class = Psr4::loadClass($className);
 			$class->controller = $this;
 			$class->actionId = $this->_action;
 			$class->input = $resource->input;
@@ -147,7 +149,7 @@ class Render
 					$className = array_shift($subRes);
 					$method = array_shift($subRes);
 
-					$class = \Qii\Autoloader\Psr4::loadClass($className);
+					$class = Psr4::loadClass($className);
 					$class->controller = $this;
 					$class->actionId = $this->_action;
 					$class->input = $resource->input;

+ 3 - 1
src/View/Requires.php

@@ -8,6 +8,8 @@
  */
 namespace Qii\View;
 
+use Qii\Config\Register;
+
 class Requires implements \Qii\View\Intf
 {
 	const VERSION = '1.2';
@@ -17,7 +19,7 @@ class Requires implements \Qii\View\Intf
 
 	public function __construct()
 	{
-		$appConfigure = \Qii\Config\Register::getAppConfigure(\Qii\Config\Register::get(\Qii\Config\Consts::APP_INI_FILE));
+		$appConfigure = Register::getAppConfigure(Register::get(\Qii\Config\Consts::APP_INI_FILE));
 		$this->viewPath = $appConfigure['view']['path'];
 	}