Satis 原理:通过配置文件生成相关库的元数据提供给composer,先通过git 下载 satis 代码库,创建一个 json 配置文件如下示例
{
"name": "longxiangam/repository", // Satis 生成的仓库的"名称",显示在 packages.json 中,通常是"我的私有仓库"这种描述性名字
"homepage": "http://composer.test", // Satis 生成的静态仓库首页 URL(浏览器访问这个地址能看到 packages.json 和搜索界面)
"repositories": [ // 指定要扫描/镜像的源仓库(可以是 git、vcs、path 等类型)
{
"type": "git",
"url": "https://github.com/longxiangam/dingtalk.git"
}
],
"require-all": false, // 关键字段:false → 不镜像"repositories"里所有包的所有版本
// 如果 true → 会镜像 repositories 里所有包的所有 commit/branch/tag 版本(非常多,适合全镜像场景)
"require": { // 关键字段:显式指定要镜像哪些包(Composer 的 require 语法)
"mingyoung/dingtalk": "*" // 只镜像这个包的所有版本(* 表示任意版本,包括所有 tag/branch)
},
"require-dependencies": false, // 是否自动镜像"require"里包的依赖(dependencies)
// false → 不镜像依赖,只镜像 mingyoung/dingtalk 本身
// true → 会递归镜像它的依赖(如它依赖 guzzlehttp/guzzle,则也会镜像 guzzle)
"require-dev-dependencies": false // 是否镜像 dev-dependencies(require-dev 里的包,如测试工具 phpunit)
// 通常设为 false,除非你想在私有仓库里也提供测试依赖
}
124747a2-8e29-4c04-99b1-209eb8a629cf
再通过命令构建出用于web发布的静态文件,命令如下, 最后两个指定配置与输出目录,构建出dist 后用nginx 发布成一个服务能够访问即可
php bin/satis build satis.json dist
在composer.json 中配置私有库
{
"repositories": [
{
"type": "composer",
"url": "http://composer.test"
}
]
}
提示 如下时
Your configuration does not allow connections to http://composer.test/packages.json. See https://getcomposer.org/doc/ 06-config.md#secure-http for details.
配置 secure-http 为false
composer config secure-http false
如果在 docker 中使用composer 要注意 配置的私有库是否能正常访问