首先让我们踏着欢快的脚步去Github创建一个新库,这里取名 composer-car,又欢快的将它克隆到本地:
$ git clone git@github.com:victorruan/composer-car.git
$ cd composer-car
这个composer-car文件夹就是你的包的根目录了,你只需要记住composer.json在包的哪个目录下面,一般那就是包的根目录了。
现在我们还没有composer.json文件,你可以根据composer文档生成并编辑它,当然composer贴心的为我们准备了命令行,look:
$ composer init
Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [root/composer-car]: victorruan/composer-car
Description []: This a demo for build composer packagist .
Author [阮佳佳 <250069802@qq.com>, n to skip]:
Minimum Stability []: dev
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
License []: MIT
Define your dependencies.
Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
{
"name": "victorruan/composer-car",
"description": "This a demo for build composer packagist .",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "阮佳佳",
"email": "250069802@qq.com"
}
],
"minimum-stability": "dev",
"require": {}
}
Do you confirm generation [yes]? yes
Would you like the vendor directory added to your .gitignore [yes]? yes
虽然经过以上的一番挣扎生成了composer.json文件,不过我们还得往里面加点东西。使用你熟悉的编辑器打开composer.json文件修改至如下:
{
"name": "victorruan/composer-car",
"description": "This a demo for build composer packagist .",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "阮佳佳",
"email": "250069802@qq.com"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.0.0"
},
"autoload": {
"psr-4": {
"Ford\\Escape\\": "src/Ford/Escape",
"Ford\\Fusion\\": "src/Ford/Fusion",
"Ford\\Focus\\": "src/Ford/Focus",
"Ford\\Fiesta\\": "src/Ford/Fiesta"
}
}
}
细心的小伙伴可能已经认出了福特的商标(Ford),这说明我们都是同道中人,你一定也很喜欢汽车,对吧对吧?