1. 创建一个开发目录
1 mkdir project 2 cd project
2. 利用composer生成一个composer.json
1 composer init 2 > Welcome to the Composer config generator 3 > This command will guide you through creating your composer.json config. 4 5 // 1. 输入项目命名空间 6 // 注意<vendor>/<name> 必须要符合 [a-z0-9_.-]+/[a-z0-9_.-]+ 7 Package name (<vendor>/<name>) [dell/htdocs]: yourname/projectname 8 9 // 2. 项目描述 10 Description []: 这是一个测试 11 12 // 3. 输入作者信息,可以直接回车 13 Author [maopanfeng <1052661052@qq.comm>, n to skip]: 14 15 // 4. 输入最低稳定版本,stable, RC, beta, alpha, dev 16 Minimum Stability []: dev 17 18 // 5. 输入项目类型, 19 Package Type (e.g. library, project, metapackage, composer-plugin) []: library 20 21 // 6. 输入授权类型 22 License []: 23 > Define your dependencies. 24 25 // 7. 输入依赖信息 26 Would you like to define your dependencies (require) interactively [yes]? 27 28 // 如果需要依赖,则输入要安装的依赖 29 Search for a package: php 30 31 // 输入版本号 32 Enter the version constraint to require (or leave blank to use the latest version): >=5.4.0 33 34 // 如需多个,则重复以上两个步骤 35 36 // 8. 是否需要require-dev, 37 Would you like to define your dev dependencies (require-dev) interactively [yes]? 38 39 // 操作同上 40 41 /* 42 { 43 "name": "mpf/test", 44 "description": "这是一个测试", 45 "type": "library", 46 "require": { 47 "php": ">=5.4.0" 48 }, 49 "license": "MIT", 50 "authors": [ 51 { 52 "name": "maopanfeng", 53 "email": "1052661052@qq.comm" 54 } 55 ], 56 "minimum-stability": "dev" 57 } 58 */ 59 60 // 9. 是否生成composer.json 61 Do you confirm generation [yes]? yes
3. 使用
1 1. 在其它项目中修改composer.json, 在require中加入 "mpf/pay": "dev-master" 2 2. 如果composer包没有上传到公有的packagelist中,需要指定源 3 - 指定方式: 4 "repositories": [ 5 { 6 "type": "vcs", 7 "url": "https://git.oschina.net/mpf/composer.git" 8 } 9 ], 10 3. 执行composer install