{"id":25829268,"url":"https://github.com/twn39/lightmoon","last_synced_at":"2025-08-02T15:09:04.166Z","repository":{"id":52406603,"uuid":"101162152","full_name":"twn39/LightMoon","owner":"twn39","description":"A framework based swoole","archived":false,"fork":false,"pushed_at":"2025-01-09T00:53:58.000Z","size":122,"stargazers_count":18,"open_issues_count":2,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T08:42:56.601Z","etag":null,"topics":["framework","php","swoole"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twn39.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-23T09:21:48.000Z","updated_at":"2024-11-20T15:08:12.000Z","dependencies_parsed_at":"2025-02-28T18:54:14.075Z","dependency_job_id":"c0fb9f40-2260-48e5-92a6-cb50165b0841","html_url":"https://github.com/twn39/LightMoon","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/twn39/LightMoon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2FLightMoon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2FLightMoon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2FLightMoon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2FLightMoon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twn39","download_url":"https://codeload.github.com/twn39/LightMoon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2FLightMoon/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268408197,"owners_count":24245577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","php","swoole"],"created_at":"2025-02-28T18:54:07.210Z","updated_at":"2025-08-02T15:09:04.128Z","avatar_url":"https://github.com/twn39.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nLightMoon是一个基于 Swoole 的微型框架，灵感来自于 Slimphp。\n\n### 设计理念\n\n简单至上，越少的代码意味着越少的 bug，此框架核心代码加上注释不足500行，路由采用 Symfony routing，依赖管理使用 pimple。\n不同的项目有不同的需求，有人会使用 MVC 全功能框架，例如 Laravel 来开发整个业务，也有人会使用 Slimphp 这种微型框架来开发 api。\n通过pimple很容易将 lightmoon 扩展为全功能框架，也可以仅仅使用核心功能来开发api。\n\n### 优势\n\nLightMoon 基于 Swoole，因此在性能方面有很大的优势，API借鉴于 Slimphp，熟悉 Slimphp 的用户能够很快上手，\n灵活容易定制，甚至可以 fork 本项目修改核心代码来满足业务需求，在能够极大地提升性能的同时，可以利用 php 完整，成熟的生态。\n\n### 缺点\n\nLightMoon 是基于 swoole，因此需要对 Swoole 有基本的了解。\n\n### 教程\n\n#### 安装\n\n```\ncomposer require lightmoon/lightmoon\n```\n\n#### 使用\n\n**简单示例**\n\n```php\n\u003c?php\n\nuse Pimple\\Container;\nuse Zend\\Config\\Config;\nuse LightMoon\\Application;\nuse Pimple\\ServiceProviderInterface;\nuse LightMoon\\Middleware\\JsonResponseMiddleware;\n\nrequire __DIR__.'/vendor/autoload.php';\n\n$config = [\n    'server' =\u003e [\n        'host' =\u003e '0.0.0.0',\n        'port' =\u003e '8060',\n        'worker_num' =\u003e 2,\n    ]\n];\n\nclass HomeController\n{\n    public function site($request, $response)\n    {\n        $response-\u003ewrite(json_encode([\n            'title' =\u003e 'hello swoole !',\n        ]));\n        return $response;\n    }\n\n    public function api($request, $response, $attr) {\n        $response-\u003ewrite(json_encode([\n            'version' =\u003e $attr['version'],\n        ]));\n\n        return $response;\n    }\n}\n\nclass HomeControllerProvider implements ServiceProviderInterface\n{\n    public function register(Container $container)\n    {\n        $container[HomeController::class] = new HomeController();\n    }\n}\n\n$app = new Application(new Config($config));\n$app-\u003eregister(new HomeControllerProvider());\n$app-\u003emiddleware(new JsonResponseMiddleware(), $priority = 10);\n\n$app-\u003eget('home', '/', HomeController::class.'@site');\n$app-\u003eget('api', '/api/{version}', HomeController::class.'@api', [\n    'version' =\u003e 'v[1-9]+'\n]);\n\n$app-\u003erun();\n```\n\n**middleware**\n\n```php\n\u003c?php\n\n$app-\u003emiddleware(function ($request, $response) {\n    $response-\u003eheader('Content-type', \"Application/json\");\n    return $response;\n}, $priority = 10);\n\n```\n\n**swoole event**\n\n```php\n\u003c?php\n\n$app-\u003eon('workerstart', function () {\n    echo \"worker started\\n\";\n});\n\n$app-\u003eon('start', function () {\n    echo \"start....\\n\";\n});\n\n```\n\n**路由**\n\n\n路由支持: `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`,\n\n```php\n$app-\u003eget('home', '/', 'HomeController@index')\n```\n\n**注册组件**\n\n创建组建：\n\n```php\nuse Pimple\\Container;\n\nclass FooProvider implements Pimple\\ServiceProviderInterface\n{\n    public function register(Container $pimple)\n    {\n        // register some services and parameters\n        // on $pimple\n    }\n}\n```\n\n注册：\n\n```php\n$app-\u003eregister(new FooProvider());\n```\n\n添加数据库：\n\nLightMoon 提供了 Eloquent ORM 封装，默认并没有启用，如需启用，可添加配置：\n\n```php\n$config = [\n    'server' =\u003e [\n        'host' =\u003e '0.0.0.0',\n        'port' =\u003e '8060',\n        'worker_num' =\u003e 2,\n    ],\n    'DB' =\u003e [\n        'driver' =\u003e 'sqlite',\n        'database' =\u003e __DIR__ . '/DB.sqlite',\n        'prefix' =\u003e '',\n        'foreign_key_constraints' =\u003e true,\n        'pool' =\u003e [\n            'size' =\u003e 3,\n        ]\n    ],\n```\n\n注入数据库服务：\n\n```php \n$app-\u003eregister(new DatabaseProvider());\n```\n\n\u003e 注：Eloquent ORM 使用的是 PDO 和 Mysqli， 所以需要开启：`Swoole\\Runtime::enableCoroutine()`。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwn39%2Flightmoon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwn39%2Flightmoon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwn39%2Flightmoon/lists"}