diff --git a/.env.example b/.env.example
index 61fc08b..2377f1d 100644
--- a/.env.example
+++ b/.env.example
@@ -45,8 +45,11 @@ password = easyphp
[app_key_map]
315b279901cc47cc21897253b7850d57 = a76adae5c3bbbc3fdf9efb8ca091b7c7
-[log_path]
+[log]
path = /runtime/logs/
+name = easy-php
+size = 512
+level= debug
[swoole]
worker_num = 5
diff --git a/README-CN.md b/README-CN.md
index 2972bb1..601fc36 100644
--- a/README-CN.md
+++ b/README-CN.md
@@ -1,9 +1,9 @@
-

+

-
+
@@ -110,6 +110,9 @@ frontend [前端源码和资源目录]
├── app.vue [根组件]
├── index.template.html [前端入口文件模板]
├── store.js [vuex store文件]
+├── .babelrc [babel配置文件]
+├── webpack.config.js [webpack配置文件]
+├── yarn.lock [yarn lock文件]
jobs [脚本目录,写业务脚本的地方]
├── demo [模块目录]
│ ├── Demo.php [脚本演示文件]
@@ -131,12 +134,13 @@ vendor [composer目录]
.git-hooks [git钩子目录]
├── pre-commit [git pre-commit预commit钩子示例文件]
├── commit-msg [git commit-msg示例文件]
-.babelrc [babel配置文件]
+bin [自动化脚本目录]
+├── build [php打包脚本]
+├── cli [框架cli模式运行脚本]
+├── run [快速开始脚本]
.env.example [环境变量示例文件]
.gitignore [git忽略文件配置]
.travis.yml [持续集成工具travis-ci配置文件]
-build [php打包脚本]
-cli [框架cli模式运行脚本]
LICENSE [lincese文件]
logo.png [框架logo图片]
composer.json [composer配置文件]
@@ -145,9 +149,6 @@ package.json [前端依赖配置文件]
phpunit.xml [phpunit配置文件]
README-CN.md [中文版readme文件]
README.md [readme文件]
-run [快速开始脚本]
-webpack.config.js [webpack配置文件]
-yarn.lock [yarn lock文件]
```
@@ -580,6 +581,30 @@ App::$container->getSingle('mongodb');
[[file: framework/nosql/*](https://github.com/TIGERB/easy-php/tree/master/framework/nosql)]
+## 日志模块
+
+日志作为一个第三方独立的模块使用,达到模块化的目的,日志类项目地址
+
+如何使用?如下,
+
+```
+// env 配置示例
+[log]
+path = /runtime/logs/
+name = easy-php
+size = 512
+level= debug
+
+
+// 业务中如何打日志
+Log::debug('EASY PHP');
+Log::notice('EASY PHP');
+Log::warning('EASY PHP');
+Log::error('EASY PHP');
+```
+
+[[file: framework/handles/LogHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/LogHandle.php)]
+
## Swoole模式
支持swoole扩展下运行
@@ -735,7 +760,7 @@ Command:
快速开始一个demo:
```
-php cli --run
+cd bin && php cli --run
```
demo如下:
@@ -855,13 +880,16 @@ cp ./.git-hooks/* ./git/hooks
- 提供更友善的开发api帮助
- 模块支持数据库nosql自定义配置
- ORM提供更多链式操作api
-- 框架log行为进行级别分类
- 想办法解决上线部署是配置文件问题
- 基于phar文件打包部署
- ...
# DONE
+- v0.8.1(2018/06/24)
+ - 重构日志类
+ - 增加bin目录统一存放脚本文件
+
- v0.8.0(2017/12/29)
- 支持swoole扩展
- 修复微单体路由无限递归问题
@@ -890,5 +918,7 @@ cp ./.git-hooks/* ./git/hooks
## 交流群
+
+
diff --git a/README.md b/README.md
index c8eb5e7..1eb305e 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
-
+

-
+
@@ -108,6 +108,9 @@ frontend [application frontend source code directory]
├── app.vue [vue root component]
├── index.template.html [frontend entrance template file]
├── store.js [vuex store file]
+├── .babelrc [babel config file]
+├── webpack.config.js [webpack config file]
+├── yarn.lock [yarn lock file]
jobs [Jobs folder, where write you business script]
├── demo [Module folder]
│ ├── Demo.php [Job script example file]
@@ -129,12 +132,13 @@ vendor [composer vendor directory]
.git-hooks [git hooks directory]
├── pre-commit [git pre-commit example file]
├── commit-msg [git commit-msg example file]
-.babelrc [babel config file]
+bin [the auto script folder]
+├── build [build php code to phar file script]
+├── cli [run this framework with the php cli mode]
+├── run [quick start script]
.env.example [the environment variables example file]
.gitignore [git ignore config file]
.travis.yml [travis-ci config file]
-build [build php code to phar file script]
-cli [run this framework with the php cli mode]
LICENSE [lincese file]
logo.png [logo picture]
composer.json [composer file]
@@ -143,9 +147,6 @@ package.json [dependence file for frontend]
phpunit.xml [phpunit config file]
README-CN.md [readme file chinese]
README.md [readme file]
-run [quick start shell script]
-webpack.config.js [webpack config file]
-yarn.lock [yarn lock file]
```
@@ -576,6 +577,32 @@ App::$container->getSingle('memcahed');
App::$container->getSingle('mongodb');
```
+[[file: framework/nosql/*](https://github.com/TIGERB/easy-php/tree/master/framework/nosql)]
+
+## Log
+
+I make the log class like a third part module that be used by composer, the project link
+
+How to use? as follows:
+
+```
+// env config
+[log]
+path = /runtime/logs/
+name = easy-php
+size = 512
+level= debug
+
+
+// How to use in your logic
+Log::debug('EASY PHP');
+Log::notice('EASY PHP');
+Log::warning('EASY PHP');
+Log::error('EASY PHP');
+```
+
+[[file: framework/handles/LogHandle.php](https://github.com/TIGERB/easy-php/blob/master/framework/handles/LogHandle.php)]
+
## Swoole Support
This framework support swoole mode with the php extension swoole, just:
@@ -731,7 +758,7 @@ Run:
Quick Start:
```
-php cli --run
+cd bin && php cli --run
```
demo as follows:
@@ -845,7 +872,6 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/
- Provide much friendly help for user
- Module's config support module-defined mysql and nosql configuration
- ORM provide more apis
-- Make different rank for log
- Resolve config problem when publish our project
- implement auto deploy by used phar
- ...
@@ -853,6 +879,10 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/
# DONE
+- v0.8.1(2017/06/24)
+ - use easy log
+ - add folder bin
+
- v0.8.0(2017/12/29)
- use swoole
- fix infinite recursion for micromonomer router
@@ -881,4 +911,6 @@ project address: [https://github.com/TIGERB/easy-php](https://github.com/TIGERB/
# CONTACT
+
+
diff --git a/app/demo/controllers/Index.php b/app/demo/controllers/Index.php
index 83c14b1..42b853d 100644
--- a/app/demo/controllers/Index.php
+++ b/app/demo/controllers/Index.php
@@ -10,7 +10,7 @@
namespace App\Demo\Controllers;
use Framework\App;
-use Framework\Logger;
+use Easy\Log;
/**
* Index Controller
@@ -85,9 +85,21 @@ public function getInstanceFromContainerDemo()
App::$container->get('request');
// 配置对象
App::$container->getSingle('config');
- // 日志对象
- $logger = App::$container->getSingle('logger');
- $logger->write(['Easy PHP logger']);
+
+ return [];
+ }
+
+ /**
+ * 写日志实例演示
+ *
+ * @return void
+ */
+ public function log()
+ {
+ Log::debug('EASY PHP');
+ Log::notice('EASY PHP');
+ Log::warning('EASY PHP');
+ Log::error('EASY PHP');
return [];
}
diff --git a/build b/bin/build
similarity index 75%
rename from build
rename to bin/build
index a0f709d..14b1b34 100644
--- a/build
+++ b/bin/build
@@ -22,18 +22,18 @@ $ext = 'phar';
$time = date('YmdHis', time());
$packageName = "{$packageName}.{$time}.{$ext}";
-if (! file_exists(__DIR__ . '/runtime/build/')) {
- mkdir(__DIR__ . '/runtime/build/');
+if (! file_exists(__DIR__ . '/../runtime/build/')) {
+ mkdir(__DIR__ . '/../runtime/build/');
}
$phar = new Phar(
- __DIR__ . '/runtime/build/' . $packageName,
+ __DIR__ . '/../runtime/build/' . $packageName,
0,
$packageName
);
-$phar->buildFromDirectory(__DIR__ . '/', '/\.php$/');
-$phar->buildFromDirectory(__DIR__ . '/', '/\.env$/');
+$phar->buildFromDirectory(__DIR__ . '/../', '/\.php$/');
+$phar->buildFromDirectory(__DIR__ . '/../', '/\.env$/');
$phar->buildFromDirectory(__DIR__ . '/', '/^cli$/');
$webIndex = "setStub(
$webIndex
);
-echo "Build success in 'runtime/build/{$packageName}' \n";
+echo "Build success in '/..runtime/build/{$packageName}' \n";
diff --git a/cli b/bin/cli
similarity index 98%
rename from cli
rename to bin/cli
index 21fb784..c8703b6 100644
--- a/cli
+++ b/bin/cli
@@ -119,4 +119,4 @@ if (isset($input['method'])) {
$_REQUEST['argv'] = $input;
// 载入框架运行文件
-require('framework/run.php');
+require('../framework/run.php');
diff --git a/run b/bin/run
similarity index 87%
rename from run
rename to bin/run
index 586ee46..600d6d2 100755
--- a/run
+++ b/bin/run
@@ -5,7 +5,7 @@
os=$(uname -a | awk 'BEGIN{FS=" "} {print $1}')
# step 1
-yarn install
+cd ../frontend && yarn install
# step 2
DOMAIN=http://localhost:60000 npm run demo
@@ -26,4 +26,4 @@ else
fi
# step 4
-cd public && php -S "localhost:60000"
+cd ../public && php -S "localhost:60000"
diff --git a/composer.json b/composer.json
index 92f5be5..5e3a491 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "tigerb/easy-php",
"description": "A Faster Lightweight Full-Stack PHP Framework",
- "version": "0.7.1",
+ "version": "0.8.1",
"type": "framework",
"homepage": "http://php.tiegrb.cn/",
"license": "MIT",
@@ -15,7 +15,8 @@
"phpunit/phpunit": "^6.0"
},
"require": {
- "mongodb/mongodb": "^1.1"
+ "mongodb/mongodb": "^1.1",
+ "easy-framework/easy-log": "^0.1.0"
},
"scripts": {
"post-install-cmd": [
diff --git a/composer.lock b/composer.lock
index e5d0d0c..71ab5c6 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,9 +4,50 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "a38313b647d8d7975194d65677e67a46",
- "content-hash": "549e5dbbc9227ecb414ae14ab91d02c1",
+ "hash": "c7f6f8494671b000675d4cdaedae160d",
+ "content-hash": "ee333caca6044e4f6f8101e100b01e1c",
"packages": [
+ {
+ "name": "easy-framework/easy-log",
+ "version": "v0.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/easy-framework/easy-log.git",
+ "reference": "8e5301689174a6ea154c805860278833a88782e5"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://files.phpcomposer.com/files/easy-framework/easy-log/8e5301689174a6ea154c805860278833a88782e5.zip",
+ "reference": "8e5301689174a6ea154c805860278833a88782e5",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Easy\\": "/src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "TIGERB",
+ "email": "tigerbcode@gmail.com"
+ }
+ ],
+ "description": "Write log easily",
+ "homepage": "https://github.com/easy-framework",
+ "keywords": [
+ "log",
+ "php-log"
+ ],
+ "time": "2018-06-23 14:56:55"
+ },
{
"name": "mongodb/mongodb",
"version": "1.1.2",
diff --git a/framework/exceptions/CoreHttpException.php b/framework/exceptions/CoreHttpException.php
index ef69302..0e1214b 100644
--- a/framework/exceptions/CoreHttpException.php
+++ b/framework/exceptions/CoreHttpException.php
@@ -13,6 +13,7 @@
use Exception;
use Framework\App;
+use Easy\Log;
/**
* 核心http异常
@@ -75,7 +76,7 @@ public function reponse()
];
// log
- App::$container->getSingle('logger')->write($data);
+ Log::error(json_encode($data));
// response
header('Content-Type:Application/json; Charset=utf-8');
@@ -102,7 +103,7 @@ public function reponseSwoole()
];
// log
- App::$container->getSingle('logger')->write($data);
+ Log::error(json_encode($data));
// response
$reponse = App::$container->get('response-swoole');
@@ -131,7 +132,7 @@ public static function reponseErr($e)
];
// log
- App::$container->getSingle('logger')->write($data);
+ Log::error(json_encode($data));
header('Content-Type:Application/json; Charset=utf-8');
die(json_encode($data));
@@ -157,7 +158,7 @@ public static function reponseErrSwoole($e)
];
// log
- App::$container->getSingle('logger')->write($data);
+ Log::error(json_encode($data));
$reponse = App::$container->get('response-swoole');
$reponse->header('Content-Type', 'Application/json');
diff --git a/framework/handles/LogHandle.php b/framework/handles/LogHandle.php
index bd79edc..95dd41c 100644
--- a/framework/handles/LogHandle.php
+++ b/framework/handles/LogHandle.php
@@ -14,6 +14,7 @@
use Framework\App;
use Framework\Handles\Handle;
use Framework\Exceptions\CoreHttpException;
+use Easy\Log;
/**
* 框架日志处理
@@ -25,30 +26,21 @@
class LogHandle implements Handle
{
/**
- * log file path
+ * log config
*
* @var string
*/
- private $logPath = '';
+ private $logConfig = '';
/**
- * log file name
- *
- * @var string
- */
- private $logFileName = 'easy-php-framework-run';
-
- /**
- * 延时注册Logger实例到容器
+ * init the easy log
*
* @param App $app 框架实例
* @return void
*/
public function register(App $app)
{
- App::$container->setSingle('logger', function () {
- return new LogHandle();
- });
+ new LogHandle();
}
/**
@@ -63,35 +55,22 @@ public function __construct()
*
* check log path env config
*/
- $this->logPath = env('log_path');
- if (empty($this->logPath) || ! isset($this->logPath['path'])) {
+ $this->logConfig = env('log');
+ if (empty($this->logConfig)) {
+ throw new CoreHttpException(400, 'log config is not defined');
+ }
+ if (! isset($this->logConfig['path'])) {
throw new CoreHttpException(400, 'log path is not defined');
}
- $this->logPath = $this->logPath['path'];
- $this->logPath = App::$app->rootPath . $this->logPath;
- if (! file_exists($this->logPath)) {
- mkdir($this->logPath, 0777, true);
+ if (! isset($this->logConfig['name'])) {
+ throw new CoreHttpException(400, 'log name is not defined');
}
-
- /**
- * 构建日志文件名称
- *
- * build log file name
- */
- $this->logFileName .= '.' . date('Ymd', time());
- }
-
- /**
- * write log
- *
- * @param [type] $data log data
- * @return void
- */
- public function write($data = [])
- {
- easy_log(
- $data,
- $this->logPath . $this->logFileName
- );
+ if (! isset($this->logConfig['size'])) {
+ throw new CoreHttpException(400, 'log size is not defined');
+ }
+ $instance = Log::getInstance();
+ $instance->logFileName = $this->logConfig['name'];
+ $instance->logPath = App::$app->rootPath . $this->logConfig['path'];
+ $instance->logFileSize = $this->logConfig['size'];
}
}
diff --git a/framework/helper.php b/framework/helper.php
index dbacb3e..f7abb1f 100644
--- a/framework/helper.php
+++ b/framework/helper.php
@@ -40,17 +40,19 @@ function env($paramName = '')
* @param array $data 数据
* @return mixed
*/
-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) . '
';
+if (! function_exists('debug')) {
+ 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;
}
- echo ($output);
- return null;
}
/**
@@ -60,12 +62,28 @@ function dump($data = [])
* @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'
- );
+if (! function_exists('log')) {
+ 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'
+ );
+ }
+}
+
+/**
+ * debug
+ *
+ * @param array $data 数据
+ * @return void
+ */
+if (! function_exists('debug')) {
+ function debug($data = [])
+ {
+ header('Content-Type:Application;');
+ echo json_encode($data, JSON_UNESCAPED_UNICODE);
+ }
}
diff --git a/framework/router/EasyRouter.php b/framework/router/EasyRouter.php
index 03d8bd8..51db822 100644
--- a/framework/router/EasyRouter.php
+++ b/framework/router/EasyRouter.php
@@ -96,7 +96,7 @@ class EasyRouter implements Router
*
* @var string
*/
- private $executeType = '';
+ private $executeType = 'controller';
/**
* 请求uri.
@@ -186,8 +186,8 @@ public function init(App $app)
// 路由策略 the current router strategy
(new $this->routeStrategyMap[$this->routeStrategy])->route($this);
- // 判断是app还是job
- $this->isAppOrJob($this);
+ // to do 等待优化
+ $this->makeClassPath($this);
// 自定义路由判断
if ((new $this->routeStrategyMap['user-defined'])->route($this)) {
@@ -225,19 +225,14 @@ public function strategyJudge()
}
/**
- * 判断是app还是job
+ * get class path
*
* @return void
*/
- public function isAppOrJob()
+ public function makeClassPath()
{
// 任务类
if ($this->routeStrategy === 'job') {
- $className = $this->request->request('job');
- $actionName = $this->request->request('action');
- $folderName = ucfirst($this->config->config['jobs_folder_name']);
- $this->classPath = "{$folderName}\\{$this->moduleName}\\{$className}";
- $this->executeType = 'job';
return;
}
@@ -245,7 +240,6 @@ public function isAppOrJob()
$controllerName = ucfirst($this->controllerName);
$folderName = ucfirst($this->config->config['application_folder_name']);
$this->classPath = "{$folderName}\\{$this->moduleName}\\Controllers\\{$controllerName}";
- $this->executeType = 'controller';
}
/**
diff --git a/framework/router/Job.php b/framework/router/Job.php
index c2f17d3..87b1606 100644
--- a/framework/router/Job.php
+++ b/framework/router/Job.php
@@ -60,8 +60,9 @@ public function route(Router $entrance)
$entrance->actionName = $actionName;
// 获job类
- $jobName = ucfirst($jobName);
- $appName = ucfirst($entrance->config->config['jobs_folder_name']);
- $this->classPath = "{$appName}\\{$moduleName}\\{$jobName}";
+ $jobName = ucfirst($jobName);
+ $moduleName = ucfirst($moduleName);
+ $appName = ucfirst($entrance->config->config['jobs_folder_name']);
+ $entrance->classPath = "{$appName}\\{$moduleName}\\{$jobName}";
}
}
diff --git a/.babelrc b/frontend/.babelrc
similarity index 100%
rename from .babelrc
rename to frontend/.babelrc
diff --git a/frontend/.gitignore b/frontend/.gitignore
new file mode 100644
index 0000000..5323875
--- /dev/null
+++ b/frontend/.gitignore
@@ -0,0 +1,5 @@
+node_modules
+
+.tmp_staging
+
+yarn-error.log
diff --git a/package.json b/frontend/package.json
similarity index 100%
rename from package.json
rename to frontend/package.json
diff --git a/webpack.config.js b/frontend/webpack.config.js
similarity index 91%
rename from webpack.config.js
rename to frontend/webpack.config.js
index 9ca6e84..9974fc4 100644
--- a/webpack.config.js
+++ b/frontend/webpack.config.js
@@ -14,12 +14,12 @@ var domain = process.env.DOMAIN; // your domain process.env.domain
webpackConfig.entry = {
app:[
// main
- './frontend/app.js',
+ './app.js',
],
};
webpackConfig.output = {
- path: path.resolve(__dirname, './public/dist'),
+ path: path.resolve(__dirname, './../public/dist'),
publicPath: domain+'/dist/',
filename: production? '[name].[hash].js': '[name].js'
};// output
@@ -71,8 +71,8 @@ webpackConfig.plugins = [
// make index.html
new HtmlWebpackPlugin({
title: 'easy-vue',
- filename: path.resolve(__dirname, './public') + '/index.html',
- template: './frontend/index.template.html'
+ filename: path.resolve(__dirname, './../public') + '/index.html',
+ template: './index.template.html'
}),
// separate css file
new ExtractTextPlugin({
diff --git a/yarn.lock b/frontend/yarn.lock
similarity index 100%
rename from yarn.lock
rename to frontend/yarn.lock
diff --git a/logo.png b/logo.png
deleted file mode 100644
index ddef182..0000000
Binary files a/logo.png and /dev/null differ