下面由composer教程栏目给大家介绍Composer包的编写,希望对需要的朋友有所帮助!
1,有自己的github账号 2,有自己的https://packagist.org 网站的账号
laravel |--src | |-composer.php
在laravel文件下 composer init 命令 // 1. 输入项目命名空间 // 注意<vendor>/<name> 必须要符合 [a-z0-9_.-]+/[a-z0-9_.-]+ Package name (<vendor>/<name>) [dell/htdocs]: output/test= // 2. 项目描述 Description []: 这是一个测试 // 3. 输入作者信息,可以直接回车 Author [, n to skip]: sinker <2713497141@qq.com> // 4. 输入最低稳定版本,stable, RC, beta, alpha, dev Minimum Stability []: dev // 5. 输入项目类型, Package Type (e.g. library, project, metapackage, composer-plugin) []: library // 6. 输入授权类型 License []: MIT // 7. 输入依赖信息 Would you like to define your dependencies (require) interactively [yes]? // 如果需要依赖,则输入要安装的依赖 Search for a package: php // 输入版本号 Enter the version constraint to require (or leave blank to use the latest version): >=5.4.0 // 如需多个,则重复以上两个步骤 // 8. 是否需要require-dev, Would you like to define your dev dependencies (require-dev) interactively [yes]? // 操作同上 { "name": "output/test", "description": "composer", "type": "library", "license": "MIT", "authors": [ { "name": "sinker", "email": "2713497141@qq.com" } ], "minimum-stability": "dev", "require": {} } // 9. 是否生成composer.json Do you confirm generation [yes]? yes Would you like the vendor directory added to your .gitignore [yes]?
composer validate composer.json
"autoload": { "psr-4": { "Composer\\": "src/" } }
namespace Composer; ## 注意点此处要和自动加载出相同 class Test { public function save() { echo 'composer-test'; } }
git tag 1.0.0 git push --tag 打版本号
The above is the detailed content of How to write Composer package. For more information, please follow other related articles on the PHP Chinese website!