Преглед на файлове

Add Autoloader and exception

Jinhui Zhu преди 7 години
родител
ревизия
49c4b61992

+ 48 - 49
Qii/Application.php

@@ -1,38 +1,22 @@
 <?php
 namespace Qii;
 
-use \Qii\Autoloader;
-
-/**
- * Qii 框架基本库所在路径
- */
-define('Qii_DIR', dirname(__FILE__));
-/**
- * DIRECTORY_SEPARATOR 的简写
- */
-define('DS', DIRECTORY_SEPARATOR);
-/**
- * 定义包含的路径分隔符
- */
-define('PS', PATH_SEPARATOR);
-/**
- * 定义操作系统类型
- */
-define('OS', strtoupper(substr(PHP_OS, 0, 3)));
-
-define('IS_CLI', php_sapi_name() == 'cli' ? true : false);
-
-include(Qii_DIR . DS .'Autoloader'. DS . 'Factory.php');
-include(Qii_DIR . DS .'Config'. DS . 'Arrays.php');
-
 class Application 
 {
     /**
      * 存储网站配置文件内容
      *
-     * @var array $_config 配置内容
+     * @var array $config 配置内容
      */
-    protected static $_config = [];
+    protected static $config = [];
+    /**
+     * @var object $logerWriter 写日志工具
+     */
+    public $logerWriter = null;
+    /**
+     * @var string $workspace 工作目录
+     */
+    private static $workspace = './';
 
 	public function __construct()
 	{
@@ -46,19 +30,46 @@ class Application
      */
 	public static function getInstance()
 	{
-
 	    return \Qii\Autoloader\Factory::getInstance('\Qii\Application');
 	}
 
+    /**
+     * 设置网站的工作目录,可以通过此方法将网站的重要文件指向到其他目录
+     *
+     * @param string $workspace 工作目录
+     * @return $this
+     */
+    public function setWorkspace($workspace = './')
+    {
+        //此处转换成真实路径,防止workspace中引入的文件出错
+        if (!is_dir($workspace)) {
+            throw new \Qii\Exceptions\FolderDoesNotExist(\Qii::i(1045, $workspace), __LINE__);
+        }
+        $workspace = \Qii\Autoloader\Psr4::getInstance()->realpath($workspace);
+        \Qii\Autoloader\Psr4::getInstance()->removeNamespace('workspace', self::$workspace);
+        //如果配置了使用namespace就走namespace
+        self::$workspace = $workspace;
+        \Qii\Autoloader\Psr4::getInstance()->addNamespace('workspace', $workspace, true);
+        foreach (self::$paths AS $path) {
+            \Qii\Autoloader\Psr4::getInstance()->addNamespace($path, $workspace . '\\' . $path);
+        }
+
+        return $this;
+    }
+
+    public function getWorkspace()
+    {
+        return self::$workspace;
+    }
     /**
      * 设置网站配置文件
      *
      * @param array $config 配置文件
      */
-	public function setConfig($config = [])
+	public function setConfig($key, $config = [])
 	{
         \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
-            ->set('Application', $config);
+            ->set(\Qii\Consts\Config::APP_CONFIGURE . '['. $key.']', $config);
 	}
 
     /**
@@ -71,35 +82,23 @@ class Application
     {
         if(!$key) {
             return \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
-                ->get('Application');
+                ->get(\Qii\Consts\Config::APP_CONFIGURE);
         }
-
         return \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
-            ->get('Application['.$key.']');
+            ->get(\Qii\Consts\Config::APP_CONFIGURE . '['.$key.']');
     }
-
+    /**
+     * 设置Route配置
+     * @param array $route
+     */
 	public function setRoute($route = [])
     {
-        Application::$_config['route'] = $route;
+        \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
+            ->set(\Qii\Consts\Config::APP_SITE_ROUTER, $config);
     }
 	
 	public function run()
 	{
 		print_r($this->getConfig());
 	}
-
-	public static function _i()
-    {
-
-    }
-
-    /**
-     * 抛出异常
-     *
-     * @return mixed
-     */
-    public static function _e()
-    {
-        return call_user_func_array(array('\Qii\Exceptions\Errors', 'e'), func_get_args());
-    }
 }

+ 22 - 8
Qii/Autoloader/Factory.php

@@ -5,21 +5,35 @@ use \Qii\Exceptions;
 
 class Factory
 {
-    protected static $_instance = [];
-
+    /**
+     * @param array $_instance 实例化对象的存储池
+     */
+    protected static $instance = [];
+    /**
+     * 以 new \Qii\Autoloader\Factory($className)的方式实例化对象
+     */
+    public function __construct($className)
+    {
+        return Factory::getInstance($className);
+    }
+    /**
+     * 实例化对象
+     * @param string $className 类名
+     */
     public static function getInstance($className)
     {
         if(!$className)
         {
-            return \_e('CLASS_NAME_IS_NULL', $className);
+            return \Qii::e('CLASS_NAME_IS_NULL', $className);
         }
-        if(isset(Factory::$_instance[$className]) &&
-            Factory::$_instance[$className] != null
+        $className = Psr4::getInstance()->getClassName($className);
+        if(isset(Factory::$instance[$className]) &&
+            Factory::$instance[$className] != null
         ){
-            return Factory::$_instance[$className];
+            return Factory::$instance[$className];
         }
-        Factory::$_instance[$className] = new $className;
+        Factory::$instance[$className] = new $className;
 
-        return Factory::$_instance[$className];
+        return Factory::$instance[$className];
     }
 }

+ 170 - 0
Qii/Autoloader/Import.php

@@ -0,0 +1,170 @@
+<?php
+namespace Qii\Autoloader;
+
+class Import
+{
+    const VERSION = '1.3';
+    private static $loadedFiles = array();
+    private static $includeFiles = array();
+
+    /**
+     * require文件
+     *
+     * @param string $file 需要require的文件
+     * @return array|bool|void
+     */
+    public static function requires($file)
+    {
+        if (is_array($file)) {
+            return array_map(function ($n) {
+                return self::requires($n);
+            }, $file);
+        }
+        if (self::getFileLoaded($file)) return true;
+        if (file_exists($file)) {
+            self::setFileLoaded($file);
+            require $file;
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 包含文件
+     * @param string $file 文件路径
+     * @return mix
+     */
+    public static function includes($file)
+    {
+        if (is_array($file)) {
+            return array_map(function ($n) {
+                return self::includes($n);
+            }, $file);
+        }
+        if (self::getIncludeFiles($file) !== null) self::getIncludeFiles($file);
+        if (file_exists($file)) {
+            $configure = include($file);
+            self::setIncludeFiles($file, $configure);
+            return $configure;
+        }
+        return false;
+    }
+
+    /**
+     * 根据类名载入文件
+     *
+     * @param string $className 类名
+     * @return string
+     */
+    public static function requireByClass($className)
+    {
+        return \Qii\Autoloader\Psr4::getInstance()->loadFileByClass($className);
+    }
+
+    /**
+     * 载入文件夹中所有文件
+     *
+     * @param string $dir 目录
+     * @throws Qii_Exceptions_FileNotFound
+     */
+    public static function requireByDir($dir)
+    {
+        if (!is_dir($dir)) throw new \Qii\Exceptions\FileNotFound(\Qii::i(1405, $dir), __LINE__);
+        $files = self::findFiles($dir, array('php'));
+        if (isset($files['php'])) self::requires($files['php']);
+    }
+
+    /**
+     * 设置文件到加载列表
+     *
+     * @param string $file 文件
+     */
+    public static function setFileLoaded($file)
+    {
+        self::$loadedFiles[$file] = true;
+    }
+
+    /**
+     * 获取指定文件是否已经加载
+     * @param string $file 文件路径
+     * @return null
+     */
+    public static function getFileLoaded($file)
+    {
+        if (isset(self::$loadedFiles[$file])) return self::$loadedFiles[$file];
+        return false;
+    }
+
+    /**
+     * 设置include的文件到已经加载列表
+     *
+     * @param string $file 文件路径
+     */
+    public static function setIncludeFiles($file, $config)
+    {
+        self::$includeFiles[$file] = $config;
+    }
+
+    /**
+     * 获取指定文件是否已经加载
+     *
+     * @param string $file 文件路径
+     * @return bool
+     */
+    public static function getIncludeFiles($file)
+    {
+        if (isset(self::$includeFiles[$file])) {
+            return self::$includeFiles[$file];
+        }
+        return false;
+    }
+
+    /**
+     * 获取已经require及include的文件列表
+     *
+     * @return array
+     */
+    public static function getLoadedFile()
+    {
+        return array('include' => self::$includeFiles, 'requires' => self::$loadedFiles);
+    }
+
+    /**
+     * 遍历目录中的路径
+     * @param string $directory 目录
+     * @param array $directories 目录下所有的路径
+     */
+    public static function globRecursive($directory, &$directories = array())
+    {
+        foreach (glob($directory, GLOB_ONLYDIR | GLOB_NOSORT) as $folder) {
+            $directories[] = $folder;
+            self::globRecursive("{$folder}/*", $directories);
+        }
+    }
+
+    /**
+     * 返回指定目录中的文件
+     * @param string $directory 目录
+     * @param array $extensions 需要过滤的后缀名
+     * @return array
+     */
+    public static function findFiles($directory, $extensions = array())
+    {
+        self::globRecursive($directory, $directories);
+        $files = array();
+        foreach ($directories as $directory) {
+            if (count($extensions) == 0) {
+                foreach (glob("{$directory}/*.*") as $file) {
+                    $files[] = $file;
+                }
+            } else {
+                foreach ($extensions as $extension) {
+                    foreach (glob("{$directory}/*.{$extension}") as $file) {
+                        $files[$extension][] = $file;
+                    }
+                }
+            }
+        }
+        return $files;
+    }
+}

+ 0 - 415
Qii/Autoloader/Psr.php

@@ -1,415 +0,0 @@
-<?php
-namespace \Qii\Autoloader;
-
-/**
- * Psr4 规范
- *
- */
-class Psr4
-{
-    /**
-     * 将查找过的文件放入缓存
-     */
-    protected static $cachedFiles = array();
-    /**
-     * 是否使用namespace
-     */
-    protected $useNamespace = array();
-    /**
-     * 添加namespace前缀对应的目录,只要是以这个前缀开头的文件都在指定目录中去查找
-     * 前缀可以对应多个目录,找的时候会去遍历数组
-     * @var array
-     */
-    protected $prefixes = array();
-
-    /**
-     * 当前class的初始化
-     */
-    private static $_instance = null;
-
-    /**
-     * @var APP_LOAD_PREFIX 保存类到以APP_LOAD_PREFIX开头的key中
-     */
-    const APP_LOAD_PREFIX = '__qii_psr4_instance';
-    /**
-     * @var $_loadedClass 保存加载过的类
-     */
-    protected static $_loadedClass = array();
-
-    /**
-     * @var $_realpath 将转换后的路径存放到此变量中
-     */
-    protected static $_realpath = array();
-
-    /**
-     * 最后一次没有加载到文件的错误路径
-     * @var array $lastErrorLoadedFile
-     */
-    protected static $lastErrorLoadedFile = array();
-
-    /**
-     * 注册自动加载类
-     *
-     */
-    private function __construct()
-    {
-    }
-
-    /**
-     * 单例模式
-     */
-    public static function getInstance()
-    {
-        if (self::$_instance == null) {
-            self::$_instance = new self();
-        }
-        return self::$_instance;
-    }
-
-    /**
-     * 注册自动加载类
-     *
-     * @return void
-     */
-    public function register()
-    {
-        spl_autoload_register(array($this, 'loadFileByClass'));
-        return $this;
-    }
-
-    /**
-     * Setting is use namespace for class
-     *
-     * @param $prefix 以prefix前缀开头的使用namespace
-     * @param bool $useNamespace
-     * @return object $this
-     */
-    public function setUseNamespace($prefix, $useNamespace = true)
-    {
-        $this->useNamespace[$prefix] = $useNamespace;
-        return $this;
-    }
-
-    /**
-     * Adds a base directory for a namespace prefix.
-     *
-     * @param string $prefix The namespace prefix.
-     * @param string $baseDir A base directory for class files in the
-     * namespace.
-     * @param bool $prepend If true, prepend the base directory to the stack
-     * instead of appending it; this causes it to be searched first rather
-     * than last.
-     * @return void
-     */
-    public function addNamespace($prefix, $baseDir, $prepend = false)
-    {
-        // normalize namespace prefix
-        $prefix = trim($prefix, '\\') . '\\';
-
-        // normalize the base directory with a trailing separator
-        $baseDir = rtrim($baseDir, '/') . DIRECTORY_SEPARATOR;
-        $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . '/';
-
-        // initialize the namespace prefix array
-        if (isset($this->prefixes[$prefix]) === false) {
-            $this->prefixes[$prefix] = array();
-        }
-        if (in_array($baseDir, $this->prefixes[$prefix])) {
-            return $this;
-        }
-        // retain the base directory for the namespace prefix
-        if ($prepend) {
-            array_unshift($this->prefixes[$prefix], $baseDir);
-        } else {
-            array_push($this->prefixes[$prefix], $baseDir);
-        }
-        return $this;
-    }
-
-    /**
-     * 移除某一个namespace下的指定路径
-     * @param string $prefix 前缀
-     * @param string $baseDir 路径
-     * @return array
-     */
-    public function removeNameSpace($prefix, $baseDir)
-    {
-        // normalize namespace prefix
-        $prefix = trim($prefix, '\\') . '\\';
-
-        // normalize the base directory with a trailing separator
-        $baseDir = rtrim($baseDir, '/') . DIRECTORY_SEPARATOR;
-        $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . '/';
-        // initialize the namespace prefix array
-        if (isset($this->prefixes[$prefix]) === false) {
-            return false;
-        }
-        foreach ($this->prefixes[$prefix] AS $key => $dir) {
-            if ($dir == $baseDir) unset($this->prefixes[$prefix][$key]);
-        }
-        return $this->prefixes;
-    }
-
-    /**
-     * 返回namespace路径
-     */
-    public function getNamespace($prefix)
-    {
-        // normalize namespace prefix
-        $prefix = trim($prefix, '\\') . '\\';
-        if (isset($this->prefixes[$prefix])) return $this->prefixes[$prefix];
-        return '';
-    }
-
-    /**
-     * 通过文件名返回路径
-     * @param string $fileName 文件名
-     * @return string
-     */
-    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]];
-        }
-        foreach ($dirs as $baseDir) {
-            if (is_file($baseDir . DS . $fileName)) {
-                return $baseDir . DS . $fileName;
-            }
-        }
-        return $fileName;
-    }
-
-    /**
-     * 获取指定文件夹路径
-     * @param string $folder 路径
-     * @return string 路径
-     */
-    public function getFolderByPrefix($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]];
-        }
-        foreach ($dirs as $baseDir) {
-            return $baseDir . DS . $folder;
-        }
-        return $folder;
-    }
-
-    /**
-     * 通过类名加载文件
-     * @param string $class 类名
-     * @return string 文件路径
-     */
-    public function loadFileByClass($class)
-    {
-        // the current namespace prefix
-        //replace "_" to "\" use common method to load class
-        $class = str_replace("_", "\\", $class);
-        $prefix = $class;
-        // work backwards through the namespace names of the fully-qualified
-        // class name to find a mapped file name
-        while (false !== $pos = strrpos($prefix, '\\')) {
-            // retain the trailing namespace separator in the prefix
-            $prefix = substr($class, 0, $pos + 1);
-
-            // the rest is the relative class name
-            $relativeClass = substr($class, $pos + 1);
-
-            // try to load a mapped file for the prefix and relative class
-            $mappedFile = $this->loadMappedFile($prefix, $relativeClass);
-            if ($mappedFile) {
-                return $mappedFile;
-            }
-
-            // remove the trailing namespace separator for the next iteration
-            // of strrpos()
-            $prefix = rtrim($prefix, '\\');
-        };
-        //如果没有找到就在workspace中去找对应的文件 额外添加的方法
-        $mappedFile = $this->loadMappedFile('workspace\\', $class);
-        if ($mappedFile) {
-            return $mappedFile;
-        }
-        $notLoaded = isset(self::$lastErrorLoadedFile[$class]) ? self::$lastErrorLoadedFile[$class] : self::getClassName($class);
-        throw new \Qii\Exceptions\FileNotFound(\Qii::i(1405, $notLoaded), __LINE__);
-    }
-
-    /**
-     * loadClass返回真正的类名
-     *
-     * @param string $class 类名
-     */
-    public function getClassName($class)
-    {
-        //如果是不使用namespace,就将namespace转换成下划线的形式
-        $useNamespace = false;
-        //将_隔开的统一替换成namespace方式,如果不使用namespace就再替换回来
-        $class = str_replace('_', '\\', $class);
-        if (stristr($class, '\\')) {
-            $prefix = explode('\\', ltrim($class, '\\'))[0];
-            $useNamespace = isset($this->useNamespace[$prefix]) && $this->useNamespace[$prefix] ? true : false;
-        }
-        if (!$useNamespace) {
-            $class = str_replace('\\', '_', $class);
-        }
-        return $class;
-    }
-
-    /**
-     * Loads the class file for a given class name.
-     *
-     * @param string $class The fully-qualified class name.
-     * @return mixed The mapped file name on success, or boolean false on
-     * failure.
-     */
-    public function loadClass($class)
-    {
-        $args = func_get_args();
-        //去掉第一个斜杠
-        $class = array_shift($args);
-        $class = preg_replace("/^\\\\/", "", $class);
-        $class = $this->getClassName($class);
-        array_unshift($args, $class);
-
-        if (class_exists($class, false)) {
-            return call_user_func_array(array($this, 'instance'), $args);
-        }
-        if ($this->loadFileByClass($class)) {
-            return call_user_func_array(array($this, 'instance'), $args);
-        }
-        throw new \Qii\Exceptions\ClassNotFound(\Qii::i(1103, $class), __LINE__);
-    }
-
-    /**
-     * 调用静态的方法
-     * @param string $class 类名
-     * @param string $method 方法名
-     * @return mixed
-     */
-    public static function loadStatic($class, $method)
-    {
-        $args = func_get_args();
-        $class = \Qii\Autoloader\Psr4::getInstance()->getClassName(array_shift($args));
-        $method = array_shift($args);
-        return call_user_func_array(array($class, $method), $args);
-    }
-
-    /**
-     * 获取文件的绝对路径
-     * @param string $path
-     * @param bool $exists 是否使用realpath
-     * @return string  真实路径
-     */
-    public static function realpath($path)
-    {
-        if (isset(self::$_realpath[$path])) return self::$_realpath[$path];
-        $drive = '';
-        if (OS === 'WIN') {
-            $path = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $path);
-            if (preg_match('/(phar\:\\\\|[a-zA-Z]\:)(.*)/', $path, $matches)) {
-                list(, $drive, $path) = $matches;
-            } else {
-                $cwd = getcwd();
-                $drive = substr($cwd, 0, 2);
-                if (substr($path, 0, 1) != DIRECTORY_SEPARATOR) {
-                    $path = substr($cwd, 3) . DIRECTORY_SEPARATOR . $path;
-                }
-            }
-        } elseif (substr($path, 0, 1) != DIRECTORY_SEPARATOR) {
-            $path = getcwd() . DIRECTORY_SEPARATOR . $path;
-        }
-        $stack = array();
-        $parts = explode(DIRECTORY_SEPARATOR, $path);
-        foreach ($parts as $dir) {
-            if (strlen($dir) && $dir !== '.') {
-                if ($dir == '..') {
-                    array_pop($stack);
-                } else {
-                    array_push($stack, $dir);
-                }
-            }
-        }
-        $realPath = str_replace(DIRECTORY_SEPARATOR, '/', $drive . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $stack));
-        self::$_realpath[$path] = $realPath;
-        return $realPath;
-    }
-
-    /**
-     * Load the mapped file for a namespace prefix and relative class.
-     *
-     * @param string $prefix The namespace prefix.
-     * @param string $relativeClass The relative class name.
-     * @return mixed Boolean false if no mapped file can be loaded, or the
-     * name of the mapped file that was loaded.
-     */
-    protected function loadMappedFile($prefix, $relativeClass)
-    {
-        if (isset(self::$cachedFiles[$prefix . '_' . $relativeClass])) return self::$cachedFiles[$prefix . '_' . $relativeClass];
-        // are there any base directories for this namespace prefix?
-        if (isset($this->prefixes[$prefix]) === false) {
-            //if there any base directories , add self to prefix
-            $this->addNamespace($prefix, $prefix);
-            //return false;
-        }
-        $prefix = trim($prefix, '\\') . '\\';
-        $file = '';
-        // look through base directories for this namespace prefix
-        foreach ($this->prefixes[$prefix] as $baseDir) {
-            $file = str_replace("/", DS, $baseDir
-                . str_replace('\\', DS, $relativeClass)
-                . '.php');
-            // if the mapped file exists, require it
-            if ($this->requireFile($file)) {
-                self::$cachedFiles[$prefix . '_' . $relativeClass] = $file;
-                return $file;
-            }
-        }
-        self::$lastErrorLoadedFile[$relativeClass] = $file;
-        // never found it
-        return false;
-    }
-
-    /**
-     * If a file exists, require it from the file system.
-     *
-     * @param string $file The file to require.
-     * @return bool True if the file exists, false if not.
-     */
-    protected function requireFile($file)
-    {
-        return \Qii\Autoloader\Import::requires($file);
-    }
-
-    /**
-     * instance class
-     * @param string $class
-     * @return object
-     */
-    public function instance()
-    {
-        $args = func_get_args();
-        $class = array_shift($args);
-        $className = $this->getClassName($class);
-        if (isset(self::$_loadedClass[$className])) return self::$_loadedClass[$className];
-        if (!class_exists($className, false)) {
-            throw new \Qii\Exceptions\CallUndefinedClass(\Qii\Application::i('1105', $className), __LINE__);
-        }
-        $loader = new \ReflectionClass($className);
-        //try {
-        self::$_loadedClass[$className] = $instance = $loader->newInstanceArgs($args);
-        //如果有_initialize方法就自动调用_initialize方法,并将参数传递给_initialize方法
-        if ($loader->hasMethod('_initialize')) {
-            call_user_func_array(array($instance, '_initialize'), $args);
-        }
-        return $instance;
-        /*} catch (Exception $e) {
-            throw new \Exception($e->getMessage(), __LINE__);
-        }*/
-    }
-}

+ 1 - 1
Qii/Config/Register.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Consts;
+namespace Qii\Config;
 
 /**
  * 将键值保存到\Qii\Config\Register::$config中

+ 1 - 1
Qii/Exceptions/AccessDenied.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class AccessDenied extends Errors
 {

+ 1 - 1
Qii/Exceptions/Cache.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class Cache extends Errors
 {

+ 1 - 1
Qii/Exceptions/CallUndefinedClass.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class CallUndefinedClass extends Errors
 {

+ 1 - 1
Qii/Exceptions/ClassInstanceof.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class ClassInstanceof extends Errors
 {

+ 1 - 1
Qii/Exceptions/ClassNotFound.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class ClassNotFound extends Errors
 {

+ 7 - 7
Qii/Exceptions/Error.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 /**
  *
@@ -84,7 +84,7 @@ class Error
 		if ($condition) {
 			return false;
 		}
-		$appConfigure = \Qii_Config_Register::AppConfigure();
+		$appConfigure = \Qii::getConfig();
 		//如果是调试模式就直接抛出异常
 		$isDebug = $appConfigure['debug'];
 		$message = array();
@@ -98,16 +98,16 @@ class Error
 			throw new \Exception(call_user_func_array(array('\Qii', 'i'), $args), $line);
 		}
 		$errorPage = $appConfigure['errorPage'];
-		$env = \Qii_Config_Register::get(\Qii_Const_Config::APP_ENVIRON, 'dev');
+		$env = \Qii\Config\Register::get(\Qii\Consts\Config::APP_ENVIRON, 'dev');
 		if ($env != 'product' && $errorPage != null) {
 			list($controller, $action) = explode(':', $appConfigure['errorPage']);
-			$controllerCls = \Qii_Config_Register::get(\Qii_Const_Config::APP_DEFAULT_CONTROLLER_PREFIX) . '_' . $controller;
+			$controllerCls = \Qii\Config\Register::get(\Qii\Consts\Config::APP_DEFAULT_CONTROLLER_PREFIX) . '_' . $controller;
 			$action = preg_replace('/(Action)$/i', "", $action);
-			$filePath = \Qii_Autoloader_Import::requireByClass($controllerCls);
+			$filePath = \Qii\Autoloader\Import::requireByClass($controllerCls);
 			if (!is_file($filePath)) {
 				if ($env == 'product') return '';
 				\Qii_Autoloader_Import::requires(Qii_DIR . DS . 'Exceptions' . DS . 'Error.php');
-				call_user_func_array(array('\Qii_Exceptions_Error', 'index'), array($controller, $action));
+				call_user_func_array(array('\Qii\Exceptions\Error', 'index'), array($controller, $action));
 				die();
 			} else {
 				\Qii::getInstance()->request->setControllerName($controller);
@@ -141,6 +141,6 @@ class Error
 
 	public function __call($method, $args)
 	{
-		if (method_exists(self, $method)) return call_user_func_array(array('Qii_Exceptions_Error', $method), $args);
+		if (method_exists(self, $method)) return call_user_func_array(array('Qii\Exceptions\Error', $method), $args);
 	}
 }

+ 13 - 13
Qii/Exceptions/Errors.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class Errors extends \Exception
 {
@@ -47,10 +47,10 @@ class Errors extends \Exception
 			echo json_encode(array('code' => $e->getCode(), 'msg' => strip_tags($e->getMessage())), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
 			return;
 		}
-		$message[] = Qii::i('Error file', self::getRelatePath($_SERVER['SCRIPT_FILENAME'], $e->getFile()));
-		$message[] = Qii::i('Error code', $e->getCode());
-		$message[] = Qii::i('Error description', $e->getMessage());
-		$message[] = Qii::i('Error line', $e->getLine() . ' on ' . self::getLineMessage($e->getFile(), $e->getLine()));
+		$message[] = \Qii::i('Error file', self::getRelatePath($_SERVER['SCRIPT_FILENAME'], $e->getFile()));
+		$message[] = \Qii::i('Error code', $e->getCode());
+		$message[] = \Qii::i('Error description', $e->getMessage());
+		$message[] = \Qii::i('Error line', $e->getLine() . ' on ' . self::getLineMessage($e->getFile(), $e->getLine()));
 		$traceString = Qii::i('Trace as below') . '<br />';
 		$traces = explode("\n", $e->getTraceAsString());
 		foreach ($traces AS $trance) {
@@ -62,18 +62,18 @@ class Errors extends \Exception
 			$message[] = 'Referer URL:' . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : \Qii::getInstance()->request->url->getCurrentURL());
 			\Qii::getInstance()->logerWriter->writeLog($message);
 		}
-		$appConfigure = Qii_Config_Register::AppConfigure();
+		$appConfigure = Qii\Config\Register::getConfig();
 
-		$env = Qii_Config_Register::get(\Qii_Const_Config::APP_ENVIRON, 'dev');
+		$env = Qii\Config\Register::get(\Qii\Consts\Config::APP_ENVIRON, 'dev');
 		if ($env == 'product' || ($appConfigure['errorPage'] && (isset($appConfigure['debug']) && $appConfigure['debug'] == 0))) {
 			list($controller, $action) = explode(':', $appConfigure['errorPage']);
-			$controllerCls = \Qii_Config_Register::get(\Qii_Const_Config::APP_DEFAULT_CONTROLLER_PREFIX) . '_' . $controller;
+			$controllerCls = \Qii\Config\Register::get(\Qii\Consts\Config::APP_DEFAULT_CONTROLLER_PREFIX) . '_' . $controller;
 			$action = preg_replace('/(Action)$/i', "", $action);
-			$filePath = \Qii_Autoloader_Import::requireByClass($controllerCls);
+			$filePath = \Qii\Autoloader\Import::requireByClass($controllerCls);
 			if (!is_file($filePath)) {
 				if ($env == 'product') return '';
-				\Qii_Autoloader_Import::requires(Qii_DIR . DS . 'Exceptions' . DS . 'Error.php');
-				call_user_func_array(array('\Qii_Exceptions_Error', 'index'), array($controller, $action));
+				\Qii\Autoloader\Import::requires(Qii_DIR . DS . 'Exceptions' . DS . 'Error.php');
+				call_user_func_array(array('\Qii\Exceptions\Error', 'index'), array($controller, $action));
 				die();
 			} else {
 				\Qii::getInstance()->request->setControllerName($controller);
@@ -135,9 +135,9 @@ class Errors extends \Exception
 		$message = array_shift($argvs);
 		$line = (int) array_pop($argvs);
 		if ($count == 2) {
-			throw new \Qii_Exceptions_Errors($message, $line);
+			throw new \Qii\Exceptions\Errors($message, $line);
 		}
 		$message = vsprintf($message, $argvs);
-		throw new \Qii_Exceptions_Errors($message, $line);
+		throw new \Qii\Exceptions\Errors($message, $line);
 	}
 }

+ 2 - 2
Qii/Exceptions/FileNotFound.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class FileNotFound extends Errors
 {
@@ -12,6 +12,6 @@ class FileNotFound extends Errors
 	 */
 	public static function getError($e)
 	{
-
+		
 	}
 }

+ 1 - 1
Qii/Exceptions/FolderDoesNotExist.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class FolderDoesNotExist extends Errors
 {

+ 1 - 1
Qii/Exceptions/InvalidFormat.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class InvalidFormat extends Errors
 {

+ 1 - 1
Qii/Exceptions/MethodNotFound.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class MethodNotFound extends Errors
 {

+ 1 - 1
Qii/Exceptions/NotAllowed.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class NotAllowed extends Errors
 {

+ 1 - 1
Qii/Exceptions/Overwrite.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class Overwrite extends Errors
 {

+ 1 - 1
Qii/Exceptions/Response.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class Response extends Errors
 {

+ 1 - 1
Qii/Exceptions/TableException.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class TableException extends Errors
 {

+ 1 - 1
Qii/Exceptions/Unsupport.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class Unsupport extends Errors
 {

+ 1 - 1
Qii/Exceptions/Variable.php

@@ -1,5 +1,5 @@
 <?php
-namespace \Qii\Exceptions;
+namespace Qii\Exceptions;
 
 class Variable extends Errors
 {

+ 12 - 2
Qii/Functions/Funcs.php

@@ -1,6 +1,16 @@
 <?php
-use \Qii\Application;
+/**
+ * \Qii::i(.., ...)
+ * @return mixed
+ */
 function _i()
 {
-    return call_user_func_array('Application::i', func_get_args());
+    return call_user_func_array('\Qii::i', func_get_args());
+}
+/**
+ * throw new Exception
+ */
+function _e()
+{
+    return call_user_func_array('\Qii::e', func_get_args());
 }

+ 132 - 0
Qii/Language/Loader.php

@@ -0,0 +1,132 @@
+<?php
+namespace Qii\Language;
+/**
+ * 加载语言包
+ * @Author Jinhui Zhu
+ * @version 1.2
+ *
+ * Usage:
+ *    Qii::Qii_Language_Loader('load', 'error', Qii_DIR); 加载系统目录中的语言
+ *    Qii::Qii_Language_Loader('load', 'error'); 加载程序目录中的语言
+ * OR
+ *    Qii::Qii_Language_Loader()->load('error', Qii_DIR); 加载系统目录中的语言
+ *    Qii::Qii_Language_Loader()->load('error'); 加载程序目录中的语言
+ */
+class Loader
+{
+	const VERSION = 1.3;
+	/**
+	 * @var $loaded ;
+	 */
+	private $loaded;
+
+	protected static $_instance;
+
+	public function __construct()
+	{
+		return $this;
+	}
+	/**
+	 * 单例模式
+	 */
+	public static function getInstance()
+	{
+
+	    return \Qii\Autoloader\Factory::getInstance('\Qii\Language\Loader');
+	}
+
+	/**
+	 * 加载系统语言包
+	 * @param  string $package 语言包名称
+	 * @param string $dir 语言包路径 默认为当前目录
+	 * @return  Array 语言包内容
+	 */
+	public function load($package, $dir = '')
+	{
+		if(!$dir)
+		{
+			$dir = \Qii::getInstance()->getWorkspace() . DS;
+		}
+		else if ($dir == Qii_DIR)
+		{
+			$dir = Qii_DIR . DS . 'Language' . DS;
+		}
+		else
+		{
+			$dir = $dir . DS;
+		}
+
+		//先获取语言配置信息
+		$language = \Qii\Autoloader\Import::includes($dir . 'i18n' . DS . 'language.php');
+		//如果是cli模式就使用英文
+		if(IS_CLI) $language = "EN";
+		$fileName = $dir . 'i18n' . DS . $language . DS . $package . '.php';
+		if (isset($this->loaded[$fileName])) return;
+		$this->loaded[$fileName] = true;
+		if (is_file($fileName)) {
+			return $this->merge($fileName);
+		}
+		throw new \Qii\Exceptions\FileNotFound(\Qii::i(1405, $fileName), __LINE__);
+	}
+
+	/**
+	 * 将语言包内容保存到系统Language中
+	 * @param string $fileName 文件名
+	 */
+	protected function merge($fileName)
+	{
+		$data = \Qii\Config\Register::get(\Qii\Consts\Config::APP_LANGUAGE_CONFIG);
+		if (!is_file($fileName)) throw new Exceptions(\Qii::i(1405, $fileName));
+		$merge = (array) \Qii\Autoloader\Import::includes($fileName);
+		
+		if ($data) $merge = $data + $merge;
+		\Qii\Config\Register::set(\Qii\Consts\Config::APP_LANGUAGE_CONFIG, $merge);
+	}
+
+	/**
+	 * 获取语言内容
+	 * @param Mix $code
+	 * @return String
+	 */
+	public function get($code)
+	{
+		$data = \Qii\Config\Register::get(\Qii\Consts\Config::APP_LANGUAGE_CONFIG, array());
+		if (isset($data) && isset($data[$code])) {
+			return $data[$code];
+		}
+		return $code;
+	}
+
+	/**
+	 * sprintf 格式化语言信息内容
+	 * Qii::i(key, '格式化语言信息内容');
+	 * @return String
+	 */
+	public function i()
+	{
+		$args = func_get_args();
+		$message = array_shift($args);
+		$message = $this->get($message);
+		$vmessage = vsprintf($message, $args);
+
+		if ($vmessage == $message && is_array($args) && count($args) > 0 && !(count($args) == 1 && $args[0] == '')) {
+			return ' ['. $message .'] ['.join("\t", $args) . ']';
+		}
+		return $vmessage;
+	}
+
+	/**
+	 * 获取语言内容,支持vsprintf
+	 *
+	 * @param String $words
+	 * @param String $code
+	 * @param argvs vsprintf的格式化参数
+	 * @return String
+	 */
+	public function gettext($code, $argvs = null)
+	{
+		if ($argvs == null) return $this->get($code);
+		return vsprintf($this->get($code), $argvs);
+	}
+
+}

+ 101 - 0
Qii/Language/i18n/CN/error.php

@@ -0,0 +1,101 @@
+<?php
+/**
+ *
+ * 400 Invalid syntax. 语法问题
+ * 401 Access denied. 访问拒绝
+ * 402 Payment required. 必须完整
+ * 403 Request forbidden. 请求被禁止
+ * 404 Object not found. 对象没有找到
+ * 405 Method is not allowed. 方法不允许
+ * 406 No response acceptable to client found. 客户端没有响应
+ * 407 Proxy authentication required. 代理需要验证
+ * 408 Server timed out waiting for request. 等等请求时服务器断开连接
+ * 409 User should resubmit with more info. 有冲突用户应该进行检查
+ * 410 Resource is no longer available. 资源不可用
+ * 411 Server refused to accept request without a length. 服务器拒绝接受没有长度的请求
+ * 412 Precondition given in request failed. 放弃请求失败的条件
+ * 413 Request entity was too large. 请求太大
+ * 414 Request Uniform Resource Identifier (URI) too long. 请求的URI 太长
+ * 415 Unsupported media type. 不支持MEDIA类型
+ * 449 Retry after doing the appropriate action. 在作了适当动作后重试
+ * 500 Internal server error. 服务器内部错误
+ * 501 Server does not support the functionality required to fulfill the request. 服务器不支持请求的功能
+ * 502 Error response received from gateway. 从网关收到错误应答
+ * 503 Temporarily overloaded. 过载
+ * 504 Timed out waiting for gateway. 等待网关时请求断开
+ * 505 HTTP version not supported. 不支持HTTP的版本
+ */
+return array(
+    //系统错误
+    -1 => '%s',
+    0 => '未知错误%d',
+    //网络相关
+    400 => '400 语法问题',
+    401 => '401 访问拒绝',
+    403 => '403 请求被禁止',
+    404 => '404 对象没有找到',
+    405 => '405 方法不允许',
+    406 => '406 客户端没有响应',
+    407 => '407 代理需要验证',
+    408 => '408 等等请求时服务器断开连接',
+    409 => '409 有冲突用户应该进行检查',
+    410 => '410 资源不可用',
+    412 => '412 放弃请求失败的条件',
+    413 => '413 请求太大',
+    414 => '414 请求的URI 太长',
+    415 => '415 不支持MEDIA类型',
+    449 => '449 在作了适当动作后重试',
+    500 => '500 服务器内部错误',
+    501 => '501 服务器不支持请求的功能',
+    502 => '502 从网关收到错误应答',
+    503 => '503 过载',
+    504 => '504 等待网关时请求断开',
+    505 => '505 不支持HTTP的版本',
+    //系统错误
+    1000 => '文件 <font color="red">%s</font>格式不正确',
+    1001 => '错误页面<font color="red">%s</font>不存在',
+    1002 => '安全校验失败',
+    1003 => '参数未定义',
+    1004 => 'memcache扩展没有加载',
+    1005 => '连接服务器[%s:%s] 失败',
+    1006 => 'redis扩展没有加载',
+    1007 => '未定义缓存策略',
+    1008 => '%s扩展没有加载',
+    1009 => '文件夹%s不存在',
+    //类相关
+    1100 => '%s参数太多,此方法只接受<font color="red">%d</font>个参数,传递了<font color="red">%d</font>个。',
+    1101 => '方法<font color="red">%s</font>未定义',
+    1103 => '未找到类<font color="red">%s</font>',
+    1104 => '类名不能为空',
+    1105 => '类<font color="red">%s</font>未被实例化',
+    1106 => '调用不存在的方法:<font color="red">%s::%s</font> 参数:<font color="red">%s</font>"',
+    1107 => '%s必须扩展或继承%s类',
+    1108 => '请在你的项目下添加此控制器<font color="red">%s</font>, 并添加此方法<font color="red">%s</font>',
+    1109 => '请在你的项目下添加<font color="red">%s</font>类, 并添加此方法<font color="red">%s</font>',
+    //文件相关
+    1400 => '网站配置文件%s错误',
+    1401 => '目录%s不存在',
+    1402 => '未指定数据库配置文件',
+    1403 => '未配置数据库',
+    1404 => '在<font color="red">%s</font>目录下未找到文件<font color="red">%s</font>',
+    1405 => '文件<font color="red">%s</font>不存在',
+    1406 => '配置信息不能为空',
+    //model相关
+    1500 => '连接数据库失败, 数据库服务器 %s, 用户名 %s, 密码 %s, 数据库 %s, 错误信息:%s',
+    1501 => '数据库连接失败, %s',
+    1506 => '数据库方法%s不存在',
+    1507 => '请先调用%s方法',
+    1508 => '数据表必须包含字段 %s',
+    1509 => '执行SQL:<font color="red">%s</font>出错, 错误描述 <font color="red">%s</font>',
+    1510 => '未指定数据表名称',
+    1511 => '数据%s已存在',
+    1512 => '数据%s不存在',
+    1513 => '未设置主键',
+
+    5001 => '%s变量未定义',
+    5002 => '%s 操作不允许',
+    5003 => '%s不能为空',
+    5004 => '%s格式不正确',
+    5005 => '%s验证规则不存在',
+
+);

+ 17 - 0
Qii/Language/i18n/CN/exception.php

@@ -0,0 +1,17 @@
+<?php
+return array(
+	'Welcome to Qii!' => '欢迎使用Qii',
+	'Show Message' => '消息列表',
+	'Throw Exception' => '出错啦',
+	'The page you are looking at is being generated dynamically by Qii' => '<small style="color:#9c9ea1;">此页面由Qii自动生成</small>',
+	'Error information' => '错误信息',
+	'Error file' => '错误文件 :%s',
+	'Error code' => '错误代码 :%s',
+	'Error line' => '错误行 :%s',
+	'Error description' => '错误描述 :%s',
+	'Trace as below' => '错误追踪如下:',
+	'qii execute footer' => '<p style="text-align:center;color:#9c9ea1;"><small>服务器软件:%s , 页面执行 %s seconds, 内存使用量 %s. 作者: %s 邮箱地址 : %s</small></p>',
+	'Please set rules first' => '请先设置规则',
+	'Invalid %s format' => '%s 格式错误',
+	'Unsupport method' => '不支持%s方法',
+);

+ 15 - 0
Qii/Language/i18n/CN/resource.php

@@ -0,0 +1,15 @@
+<?php
+return array(
+    '10001' => '两个值不相同',
+    '100000' => '参数错误',
+    '100001' => '未设置资源文件',
+    '100002' => '未设置标题',
+    '100003' => '未设之资源',
+    '100004' => '参数指定错误',
+    '100005' => '文件移动失败',
+    '100006' => '文件夹不存在',
+    '100007' => '创建文件夹失败',
+    '100008' => '文件上传失败',
+    '100009' => '验证码错误',
+	'100010' => '错误的日志类型 %s ',
+);

+ 99 - 0
Qii/Language/i18n/EN/error.php

@@ -0,0 +1,99 @@
+<?php
+/**
+ *
+ * 400 Invalid syntax. 语法问题
+ * 401 Access denied. 访问拒绝
+ * 402 Payment required. 必须完整
+ * 403 Request forbidden. 请求被禁止
+ * 404 Object not found. 对象没有找到
+ * 405 Method is not allowed. 方法不允许
+ * 406 No response acceptable to client found. 客户端没有响应
+ * 407 Proxy authentication required. 代理需要验证
+ * 408 Server timed out waiting for request. 等等请求时服务器断开连接
+ * 409 User should resubmit with more info. 有冲突用户应该进行检查
+ * 410 Resource is no longer available. 资源不可用
+ * 411 Server refused to accept request without a length. 服务器拒绝接受没有长度的请求
+ * 412 Precondition given in request failed. 放弃请求失败的条件
+ * 413 Request entity was too large. 请求太大
+ * 414 Request Uniform Resource Identifier (URI) too long. 请求的URI 太长
+ * 415 Unsupported media type. 不支持MEDIA类型
+ * 449 Retry after doing the appropriate action. 在作了适当动作后重试
+ * 500 Internal server error. 服务器内部错误
+ * 501 Server does not support the functionality required to fulfill the request. 服务器不支持请求的功能
+ * 502 Error response received from gateway. 从网关收到错误应答
+ * 503 Temporarily overloaded. 过载
+ * 504 Timed out waiting for gateway. 等待网关时请求断开
+ * 505 HTTP version not supported. 不支持HTTP的版本
+ */
+return array(
+	-1 => '%s',
+	0 => 'Unknow error %d',
+	//network
+	400 => '400 Bad request.',
+	401 => '401 Access denied.',
+	403 => '403 Request forbidden.',
+	404 => '404 Not found.',
+	405 => '405 Method is not allowed.',
+	406 => '406 No response acceptable to client found.',
+	407 => '407 Proxy authentication required.',
+	408 => '408 Server timed out waiting for request.',
+	409 => '409 User should resubmit with more info.',
+	410 => '410 Resource is no longer available. ',
+	412 => '412 Precondition given in request failed.',
+	413 => '413 Request entity was too large.',
+	414 => '414 Request Uniform Resource Identifier (URI) too long.',
+	415 => '415 Unsupported media type.',
+	449 => '449 Retry after doing the appropriate action.',
+	500 => '500 Internal server error ',
+	501 => '501 Server does not support the functionality required to fulfill the request',
+	502 => '502 Error response received from gateway',
+	503 => '503 Temporarily overloaded.',
+	504 => '504 Timed out waiting for gateway.',
+	505 => '505 HTTP version not supported.',
+	//system relate
+	1000 => 'The file <font color="red">%s</font> format is wrong',
+	1001 => 'Error page <font color="red">%s</font> does not exist',
+	1002 => 'Security check failure',
+	1003 => 'Undefined variable',
+	1004 => 'The memcache extension must be loaded before use',
+	1005 => 'Connect memcached server [%s:%s] failed',
+	1006 => 'The redis extension must be loaded before use',
+	1007 => 'Undefined cache policy',
+	1008 => 'The %s extension must be loaded before use',
+    1009 => 'Folder "%s" does not exist',
+	//class relate
+	1100 => 'Two many argements in %s , this method need %d parameter, %d given',
+	1101 => 'Call undefined method <font color="red">%s</font>',
+	1102 => 'Class <font color="red">%s</font> does not exist',
+	1103 => 'Class name couldn\'t be NULL',
+	1104 => 'Class <font color="red">%s</font> didn\'t instance',
+	1105 => 'Call undefined method <font color="red">%s::%s</font>" with args "<font color="red">%s</font>"',
+	1107 => 'Class %s must be the extends/implements of %s',
+	1108 => 'Please write this controller<font color="red">%s</font> controller in your project, and add this method <font color="red">%s</font>',
+	1109 => 'Please write this <font color="red">%s</font> class in your project, and add this method <font color="red">%s</font>',
+	//file and others
+	1400 => 'Website configure file <font color="red">%s</font> error',
+	1401 => 'Dir %s does not exist',
+	1402 => 'No database configure file',
+	1403 => 'No database configure',
+	1404 => 'Directory <font color="red">%s</font> not included file <font color="red">%s</font>',
+	1405 => 'File %s not found',
+	1406 => 'Configure file is empty',
+	//model
+	1500 => 'Connect Database fail, host:%s, use user:%s, password:%s, database:%s error : %s',
+	1501 => 'Connect Database fail, %s',
+	1506 => 'Model\'s method %s does not exist',
+	1507 => 'Please call %s method first',
+	1508 => 'Table must have some fields',
+	1509 => 'Execute Query error with sql : <font color="red">%s</font>, Error description: <font color="red">%s</font>',
+	1510 => 'unknow table name',
+	1511 => '%s does exist',
+	1512 => '%s does not exist',
+	1513 => 'private key is not set',
+
+	5001 => '%s undefined',
+	5002 => '%s not allowed',
+	5003 => '%s is null',
+	5004 => '%s is invalid',
+	5005 => '%s regular does not exist'
+);

+ 17 - 0
Qii/Language/i18n/EN/exception.php

@@ -0,0 +1,17 @@
+<?php
+return array(
+	'Welcome to Qii!' => 'Welcome to Qii!',
+	'Show Message' => 'Show Message',
+	'Throw Exception' => 'Throw Exception',
+	'The page you are looking at is being generated dynamically by Qii' => '<small style="color:#9c9ea1;">The page you are looking at is being generated dynamically by Qii</small>',
+	'Error information' => 'Error information',
+	'Error file' => 'Error file :%s',
+	'Error code' => 'Error code:%s',
+	'Error line' => 'Error line :%s',
+	'Error description' => 'Error description :%s',
+	'Trace as below' => 'Trace as below :',
+	'qii execute footer' => '<p style="text-align:center;color:#9c9ea1;"><small>%s , Page rendered in %s seconds, Use memory %s. Author: %s Email : %s</small></p>',
+	'Please set rules first' => 'Please set rules first',
+	'Invalid %s format' => 'Invalid %s format',
+	'Unsupport method' => 'Unsupport %s method',
+);

+ 15 - 0
Qii/Language/i18n/EN/resource.php

@@ -0,0 +1,15 @@
+<?php
+return array(
+    '10001' => '两个值不相同',
+    '100000' => '参数错误',
+    '100001' => '未设置资源文件',
+    '100002' => '未设置标题',
+    '100003' => '未设之资源',
+    '100004' => '参数指定错误',
+    '100005' => '文件移动失败',
+    '100006' => '文件夹不存在',
+    '100007' => '创建文件夹失败',
+    '100008' => '文件上传失败',
+    '100009' => '验证码错误',
+	'100010' => '错误的日志类型 %s ',
+);

+ 2 - 0
Qii/Language/i18n/language.php

@@ -0,0 +1,2 @@
+<?php
+return 'CN';

+ 5 - 4
public/index.php

@@ -1,5 +1,6 @@
 <?php
-require_once('../Qii/Application.php');
-$app = \Qii\Application::getInstance();
-$app->setConfig('site', ['env' => 'product']);
-$app->run();
+require_once('../Qii/Qii.php');
+$app = \Qii::getInstance();
+$app->setConfig('site', ['env' => 'product', ['siteName' => 'Qii'] ]);
+$app->run();
+new s();