Laravel 如何利用composer更新git远程仓库的自定义包
如何利用Composer更新git远程仓库的自定义包
1、在你自己开发的包目录下新建一个 composer.json 文件:
composer.json:
提示:你的远程仓库中必须有composer.json文件和版本号
composer.json内容:
{ "name": "eshow/element", "description": "for element manager", "type": "library", "require": { "php-ffmpeg/php-ffmpeg": "^0.9.5",//你这个包里所需要的依赖 "predis/predis": "^1.1"//所需要的文件 }, "autoload":{ "psr-4":{ "Eshow\\Element\\":"src/"//自动加载 } } }
git打包提交到远程服务器
git tag:
如何打版本号?
在你本地项目中 Shit+鼠标右键,在此打开命令行,输入命令:
$ git tag -a 0.1.3
输入 注释:0.1.3,或者别的自己定义
$ git push --tags
提交到远程服务器
2、composer 更新远程git代码
在你本地项目中的composer.json中加入红色标注的:
{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=5.6.4", "laravel/framework": "5.4.*", "laravel/tinker": "~1.0", "php-ffmpeg/php-ffmpeg": "^0.9.5", "eshow/element": "~0.2" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.*", "phpunit/phpunit": "~5.7" }, "autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "scripts": { "post-root-package-install": [ "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "php artisan key:generate" ], "post-install-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postInstall", "php artisan optimize" ], "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan optimize" ] }, "config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true, "secure-http": false }, "repositories":[ { "type":"git", "url":"http://106.2.200.206/linyan/element_package.git" } ] }
注意:composer 操作的时候默认的 secure-http 的属性为 True,只有https的链接才能被下载,默认源为http协议。所以在composer.json中添加:"config":{"secure-http":false}能解决问题。
输入单个包更新命令:
$ composer update "eshow/element"
更新成功了
如果 composer install 失败,删除 composer.lock 文件,重新来!