{"id":20441735,"url":"https://github.com/mix-php/cli-skeleton","last_synced_at":"2025-08-21T06:44:50.938Z","repository":{"id":57017776,"uuid":"392896476","full_name":"mix-php/cli-skeleton","owner":"mix-php","description":"CLI development skeleton","archived":false,"fork":false,"pushed_at":"2023-04-19T02:02:52.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-16T00:10:35.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mix-php.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":"2021-08-05T03:59:57.000Z","updated_at":"2022-04-15T15:32:21.000Z","dependencies_parsed_at":"2024-11-15T09:48:48.448Z","dependency_job_id":null,"html_url":"https://github.com/mix-php/cli-skeleton","commit_stats":{"total_commits":20,"total_committers":3,"mean_commits":6.666666666666667,"dds":0.09999999999999998,"last_synced_commit":"e94698918a1d0c5434788c0c482a90d8dc7410be"},"previous_names":[],"tags_count":13,"template":true,"template_full_name":null,"purl":"pkg:github/mix-php/cli-skeleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fcli-skeleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fcli-skeleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fcli-skeleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fcli-skeleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-php","download_url":"https://codeload.github.com/mix-php/cli-skeleton/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fcli-skeleton/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271437252,"owners_count":24759524,"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-21T02:00:08.990Z","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":[],"created_at":"2024-11-15T09:34:28.983Z","updated_at":"2025-08-21T06:44:45.892Z","avatar_url":"https://github.com/mix-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLI development skeleton\n\n帮助你快速搭建 CLI 项目骨架，并指导你如何使用该骨架的细节，骨架默认开启了 SQL、Redis 日志，压测前请先关闭 `.env` 的 `APP_DEBUG`\n\n## 安装\n\n```\ncomposer create-project --prefer-dist mix/cli-skeleton cli\n```\n\n## 快速开始\n\n使用 `composer` 执行命令\n\n```\ncomposer run-script --timeout=0 cli:clearcache\n```\n\n## 执行脚本\n\n- `composer run-script` 命令中的 `--timeout=0` 参数是防止 composer [执行超时](https://getcomposer.org/doc/06-config.md#process-timeout)\n- `composer.json` 定义了命令执行脚本，对应上面的执行命令\n\n```json\n\"scripts\": {\n    \"cli:clearcache\": \"php bin/cli.php clearcache\"\n}\n```\n\n当然也可以直接下面这样启动，效果是一样的，但是 `scripts` 能帮你记录到底有哪些可用的命令，同时在IDE中调试更加方便。\n\n```\nphp bin/cli.php clearcache\n```\n\n## 编写一个 CLI 程序\n\n首先我们在 `bin/cli.php` 入口文件中增加一个命令\n\n- 如何配置命令：[mix/cli](https://github.com/mix-php/cli#readme)\n\n```php\nCli::setName('app')-\u003esetVersion('0.0.0-alpha');\n$cmds = [\n    new Mix\\Cli\\Command([\n        'name' =\u003e 'clearcache',\n        'short' =\u003e 'Clear cache',\n        'options' =\u003e [\n            new Mix\\Cli\\Option([\n                'names' =\u003e ['k', 'key'],\n                'usage' =\u003e 'Key name'\n            ]),\n        ],\n        'run' =\u003e new App\\Command\\ClearCache(),\n    ])\n];\nCli::addCommand(...$cmds)-\u003erun();\n```\n\n查看命令帮助，检查配置是否正确\n\n```\n$ php bin/cli.php \nUsage: bin/cli.php [OPTIONS] COMMAND [ARG...]\n\nCommands:\n  clearcache    Clear cache\n\nGlobal Options:\n  -h, --help    Print usage\n  -v, --version Print version information\n\nRun 'bin/cli.php COMMAND --help' for more information on a command.\n\nDeveloped with Mix PHP framework. (openmix.org/mix-php)\n```\n\n执行 `clearcache` 命令\n\n```\n$ php bin/cli.php clearcache\n```\n\n## 使用容器中的对象\n\n容器采用了一个简单的单例模式，你可以修改为更加适合自己的方式。\n\n- 数据库：[mix/database](https://github.com/mix-php/database#readme)\n\n```\nDB::instance()\n```\n\n- Redis：[mix/redis](https://github.com/mix-php/redis#readme)\n\n```\nRDS::instance()\n```\n\n- 日志：[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)\n\n```\nLogger::instance()\n```\n\n- 配置：[hassankhan/config](https://github.com/hassankhan/config#getting-values)\n\n```\nConfig::instance()\n```\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fcli-skeleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-php%2Fcli-skeleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fcli-skeleton/lists"}