diff --git a/.env b/.env.example similarity index 100% rename from .env rename to .env.example diff --git a/.gitignore b/.gitignore index 3b95611..e844902 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ vendor -.env.prod +.env node_modules diff --git a/README-CN.md b/README-CN.md index 4ff8331..0c02e0f 100644 --- a/README-CN.md +++ b/README-CN.md @@ -3,7 +3,7 @@
- + @@ -607,6 +607,7 @@ require('runtime/build/App.20170505085503.phar'); 执行: - composer install +- cp .env.example .env - chmod -R 777 runtime **网站服务模式:** @@ -655,9 +656,6 @@ cp ./.git-hooks/* ./git/hooks # TODO -- 懒加载优化框架加载流程 -- 性能测试和优化 -- 变更Helper助手类的成员方法为框架函数,简化使用提高生产效率 - 提供更友善的开发api帮助 - 模块支持数据库nosql自定义配置 - 支持mysql主从配置 @@ -666,3 +664,11 @@ cp ./.git-hooks/* ./git/hooks - 想办法解决上线部署是配置文件问题 - 基于phar文件和git webhook自动化打包部署 - ... + +# DONE + +- v0.6.7(2017/05/14) + - 修复未设置默认时区 + - 懒加载优化框架加载流程 + - 变更Helper助手类的成员方法为框架函数,简化使用提高生产效率 + - 性能测试和优化 diff --git a/README.md b/README.md index 0016fd0..67c3a85 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@
- + @@ -604,6 +604,7 @@ require('runtime/build/App.20170505085503.phar'); Run: - composer install +- cp .env.example .env - chmod -R 777 runtime **Web Server Mode:** @@ -648,9 +649,6 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/ # TODO -- The performance test and optimize -- Use the lazy load thought to optimize the framework -- Change Helper's method to the framework's function - Provide much friendly help for user - Module's config support module-defined mysql and nosql configuration - Support master-salve mysql configuration @@ -659,3 +657,12 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/ - Resolve config problem when publish our project - implement auto deploy by used phar and git webhook - ... + + +# DONE + +- v0.6.7(2017/05/14) + - fix not set default time zone + - The performance test and optimize + - Use the lazy load thought to optimize the framework + - Change Helper's method to the framework's function diff --git a/app/demo/controllers/Index.php b/app/demo/controllers/Index.php index 59b15aa..90e06fe 100644 --- a/app/demo/controllers/Index.php +++ b/app/demo/controllers/Index.php @@ -10,7 +10,6 @@ namespace App\Demo\Controllers; use Framework\App; -use Framework\Helper; use Framework\Loger; /** diff --git a/composer.json b/composer.json index 9c67093..d58acfc 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "TIGERB/easy-php", "description": "A lightweight PHP framework for studying", - "version":"0.3.6", - "type": "framework", + "version":"0.6.7", + "type": "framework, easy-php, php framework", "authors": [ { "name": "tigerb", diff --git a/config/database.php b/config/database.php index 0f4be73..91ed125 100644 --- a/config/database.php +++ b/config/database.php @@ -9,16 +9,14 @@ * * ********************************************/ -use Framework\Helper; - return [ /* 默认配置 */ 'database' => [ - 'dbtype' => Helper::env('database')['dbtype'], - 'dbprefix' => Helper::env('database')['dbprefix'], - 'dbname' => Helper::env('database')['dbname'], - 'dbhost' => Helper::env('database')['dbhost'], - 'username' => Helper::env('database')['username'], - 'password' => Helper::env('database')['password'] + 'dbtype' => env('database')['dbtype'], + 'dbprefix' => env('database')['dbprefix'], + 'dbname' => env('database')['dbname'], + 'dbhost' => env('database')['dbhost'], + 'username' => env('database')['username'], + 'password' => env('database')['password'] ] ]; diff --git a/config/nosql.php b/config/nosql.php index 9843601..37d002f 100644 --- a/config/nosql.php +++ b/config/nosql.php @@ -13,44 +13,42 @@ * nosql相关配置 */ -use Framework\Helper; - return [ // 需要提供支持的nosql种类 // 参数示例:redis,memcached,mongoDB - 'nosql' => Helper::env('nosql')['support'], + 'nosql' => env('nosql')['support'], // redis 'redis' => [ // 默认host - 'host' => Helper::env('redis')['host'], + 'host' => env('redis')['host'], // 默认端口 - 'port' => Helper::env('redis')['port'], + 'port' => env('redis')['port'], // 密码 - 'password' => Helper::env('redis')['password'], + 'password' => env('redis')['password'], ], // memcached 'memcached' => [ // 默认host - 'host' => Helper::env('memcached')['host'], + 'host' => env('memcached')['host'], // 默认端口 - 'port' => Helper::env('memcached')['port'], + 'port' => env('memcached')['port'], // 密码 - 'password' => Helper::env('memcached')['password'], + 'password' => env('memcached')['password'], ], // mongoDB 'mongoDB' => [ // 默认host - 'host' => Helper::env('mongoDB')['host'], + 'host' => env('mongoDB')['host'], // 默认端口 - 'port' => Helper::env('mongoDB')['port'], + 'port' => env('mongoDB')['port'], // 数据库名称 - 'database' => Helper::env('mongoDB')['database'], + 'database' => env('mongoDB')['database'], // 用户名 - 'username' => Helper::env('mongoDB')['username'], + 'username' => env('mongoDB')['username'], // 密码 - 'password' => Helper::env('mongoDB')['password'], + 'password' => env('mongoDB')['password'], ] ]; diff --git a/framework/Helper.php b/framework/Helper.php deleted file mode 100644 index 37e4dc8..0000000 --- a/framework/Helper.php +++ /dev/null @@ -1,84 +0,0 @@ - * - * * - ********************************************/ - -namespace Framework; - -use Framework\App; - -/** - * 框架助手类 - * - * Framework's helper class - * - * 工具类 - * - * Tool class - */ -class Helper -{ - /** - * 环境参数缓存 - * - * @var array - */ - private static $envCache = []; - - /** - * 获取环境参数 - * - * @param string $paramName 参数名 - * @return mixed - */ - public static function env($paramName = '') - { - if (array_key_exists($paramName, self::$envCache)) { - return self::$envCache[$paramName]; - } - self::$envCache[$paramName] = App::$container->getSingle('request')->env($paramName); - return self::$envCache[$paramName]; - } - - /** - * 浏览器友善的打印数据 - * - * @param array $data 数据 - * @return mixed - */ - public static function dump($data = []) - { - ob_start(); - var_dump($data); - $output = ob_get_clean(); - if (!extension_loaded('xdebug')) { - $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); - $output = '
' . htmlspecialchars($output, ENT_QUOTES) . ''; - } - echo ($output); - return null; - } - - /** - * log - * - * @param array $data log数据 - * @param string $fileName log文件名 绝对路径 - * @return void - */ - public static function log($data = [], $fileName = 'debug') - { - $time = date('Y-m-d H:i:s', time()); - error_log( - "[{$time}]: " . json_encode($data, JSON_UNESCAPED_UNICODE)."\n", - 3, - $fileName . '.log' - ); - } -} diff --git a/framework/Request.php b/framework/Request.php index c6a2fe0..1b1f479 100644 --- a/framework/Request.php +++ b/framework/Request.php @@ -210,7 +210,7 @@ public function get($value = '', $default = '', $checkEmpty = true) if (empty($this->getParams[$value]) && $checkEmpty) { return $default; } - return $this->getParams[$value]; + return htmlspecialchars($this->getParams[$value]); } /** @@ -229,7 +229,7 @@ public function post($value = '', $default = '', $checkEmpty = true) if (empty($this->getParams[$value]) && $checkEmpty) { return $default; } - return $this->postParams[$value]; + return htmlspecialchars($this->postParams[$value]); } /** @@ -248,7 +248,7 @@ public function request($value = '', $default = '', $checkEmpty = true) if (empty($this->getParams[$value]) && $checkEmpty) { return $default; } - return $this->requestParams[$value]; + return htmlspecialchars($this->requestParams[$value]); } /** @@ -259,6 +259,9 @@ public function request($value = '', $default = '', $checkEmpty = true) public function all() { $res = array_merge($this->postParams, $this->getParams); + foreach ($res as &$v) { + $v = htmlspecialchars($v); + } return $res; } diff --git a/framework/handles/ConfigHandle.php b/framework/handles/ConfigHandle.php index f0e1bc4..f77432d 100644 --- a/framework/handles/ConfigHandle.php +++ b/framework/handles/ConfigHandle.php @@ -78,11 +78,16 @@ public function __set($name = '', $value = '') */ public function register(App $app) { + // load helper function file + require($app->rootPath . '/framework/helper.php'); + $this->app = $app; $app::$container->setSingle('config', $this); $this->loadConfig($app); - // 加载时区 - date_default_timezone_set($this->config['default_timezone']); + + // 设置时区 + // define time zone + date_default_timezone_set($this->config['default_timezone']); } /** diff --git a/framework/handles/LogHandle.php b/framework/handles/LogHandle.php index 922cf50..bd79edc 100644 --- a/framework/handles/LogHandle.php +++ b/framework/handles/LogHandle.php @@ -13,7 +13,6 @@ use Framework\App; use Framework\Handles\Handle; -use Framework\Helper; use Framework\Exceptions\CoreHttpException; /** @@ -64,7 +63,7 @@ public function __construct() * * check log path env config */ - $this->logPath = Helper::env('log_path'); + $this->logPath = env('log_path'); if (empty($this->logPath) || ! isset($this->logPath['path'])) { throw new CoreHttpException(400, 'log path is not defined'); } @@ -90,7 +89,7 @@ public function __construct() */ public function write($data = []) { - Helper::log( + easy_log( $data, $this->logPath . $this->logFileName ); diff --git a/framework/handles/NosqlHandle.php b/framework/handles/NosqlHandle.php index d3b0ee5..c818968 100644 --- a/framework/handles/NosqlHandle.php +++ b/framework/handles/NosqlHandle.php @@ -18,12 +18,16 @@ /** * nosql处理机制 * + * nosql handle + * * @author TIERGB
' . htmlspecialchars($output, ENT_QUOTES) . ''; + } + echo ($output); + return null; +} + +/** + * log + * + * @param array $data log数据 + * @param string $fileName log文件名 绝对路径 + * @return void + */ +function easy_log($data = [], $fileName = 'debug') +{ + $time = date('Y-m-d H:i:s', time()); + error_log( + "[{$time}]: " . json_encode($data, JSON_UNESCAPED_UNICODE)."\n", + 3, + $fileName . '.log' + ); +} diff --git a/framework/nosql/Memcached.php b/framework/nosql/Memcached.php index 04d68b9..14bc966 100644 --- a/framework/nosql/Memcached.php +++ b/framework/nosql/Memcached.php @@ -22,14 +22,16 @@ class Memcached { /** - * 构造函数 + * 初始化 + * + * init */ - public function __construct() + public static function init() { $config = App::$container->getSingle('config'); $config = $config->config['memcached']; - $redis = new rootMemcached(); - $redis->addServer($config['host'], $config['port']); - App::$container->setSingle('memcached', $redis); + $memcached = new rootMemcached(); + $memcached->addServer($config['host'], $config['port']); + return $memcached; } } diff --git a/framework/nosql/MongoDB.php b/framework/nosql/MongoDB.php index 9e35f64..9ed1d1f 100644 --- a/framework/nosql/MongoDB.php +++ b/framework/nosql/MongoDB.php @@ -17,14 +17,18 @@ /** * MongoDB操作类 * + * mongodb class + * * @author TIERGB