# sws-dev **Repository Path**: sreeb/sws-dev ## Basic Information - **Project Name**: sws-dev - **Description**: sws框架初始构建版本 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 0 - **Created**: 2021-04-13 - **Last Updated**: 2022-03-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README .---. .--.--. /. ./| .--.--. / / ' .-'-. ' | / / ' | : /`./ /___/ \: | | : /`./ | : ;_ .-'.. ' ' . | : ;_ \ \ `. /___/ \: ' \ \ `. `----. \ . \ ' .\ `----. \ / /`--' / \ \ ' \ | / /`--' / '--'. / \ \ |--" '--'. / `--'---' \ \ | `--'---' '---" SWS框架 =============== > sws是基于php7.4+, swoole4.6+ 开发的学习框架。 框架支持依赖注入,路由参数绑定,路由分组,请求中间件等。代码注释详细,十分适合学习交流。欢迎有兴趣的童鞋一起开发。 ## 核心流程 > 框架启动 -> 初始化配置项 -> 初始化路由 -> 监听框架事件 -> 启动swoole服务 -> 绑定swoole事件 -> 请求进入 -> 匹配路由 -> 执行中间件 -> 执行路由目标方法 -> 获取返回结果响应给客户端 ## 启动服务 ``` php bin/sws.php http start //启动服务 php bin/sws.php http start -d //守护进程启动服务 php bin/sws.php http stop //停止服务 php bin/sws.php http restart //重启服务 php bin/sws.php http reload //热重启服务 ``` ## 核心组件 ### 协程级容器 > 开发者无需关心业务中容器内存释放,容器采用协程隔离。请求结束会自动清除协程内容器对象,无需担心内存泄漏。 ### 路由 ``` //路由目标参数支持字符串@分割类和方法,数组,闭包。 Route::get('/', 'app\controllers\Index@index')->middleware(function (Swoole\Http\Request $request, $next) { return $next($request); }); //路由参数绑定 Route::any('/test/{str:\S+}', [\app\controllers\Index::class, 'test'])->middleware(\app\middleware\TestMiddleware::class); //分组路由。 //中间件执行顺序为全局中间件->路由分组中间件->路由中间件 Route::group('/group', function () { Route::get('/index', 'app\controllers\Index@index')->middleware(function (Swoole\Http\Request $request, $next) { return $next($request); }); })->middleware([\app\middleware\TestMiddleware::class]); ``` ### 中间件 > 中间件执行顺序为 全局中间件 -> 路由分组中间件 -> 路由中间件