开发 Composer 包详细步骤(转)

一、GitHub 创建一个名 uploadfile 新仓库,并克隆至本地。
$ git clone git@github.com:guanguans/uploadfile.git
$ cd uploadfile
二、初始化项目,生成composer.json文件
2.1 步骤
yzm@Alert MINGW64 /i/phpstudy/WWW/uploadfile
$ composer init

Welcome to the Composer config generator

This command will guide you through creating your composer.json config.

Package name (/) [yzm/try-make-package]: guanguans/uploadfile
Description []: 一个通用文件上传包
Author [guanguans 53222411@qq.com, n to skip]: guanguans yzmguanguan@gmail.com
Minimum Stability []: dev
Package Type (e.g. library, project, metapackage, composer-plugin) []: l ibrary
License []: MIT

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes] ? yes
Search for a package: php
Enter the version constraint to require (or leave blank to use the lates t version): >=5.4.0
Search for a package:
Would you like to define your dev dependencies (require-dev) interactive ly [yes]? yes
Search for a package: php
Enter the version constraint to require (or leave blank to use the lates t version): >=5.4.0
Search for a package:

{
“name”: “guanguans/uploadfile”,
“description”: “一个通用文件上传包”,
“type”: “library”,
“require”: {
“php”: “>=5.4”
},
“require-dev”: {
“php”: “>=5.4”
},
“license”: “MIT”,
“authors”: [
{
“name”: “guanguans”,
“email”: “yzmguanguan@gmail.com”
}
],
“minimum-stability”: “dev”
}

Do you confirm generation [yes]? yes

2.2 步骤解释
yzm@Alert MINGW64 /i/phpstudy/WWW/uploadfile
$ composer init

Welcome to the Composer config generator

This command will guide you through creating your composer.json config.

// 1. 输入项目命名空间
// 注意/ 必须要符合 [a-z0-9_.-]+/[a-z0-9_.-]+
Package name (/) [dell/htdocs]: yourname/projectname

// 2. 项目描述
Description []: 这是一个测试

// 3. 输入作者信息,可以直接回车
Author [guanguans 53222411@qq.com, n to skip]:

// 4. 输入最低稳定版本,stable, RC, beta, alpha, dev
Minimum Stability []: dev

// 5. 输入项目类型,
Package Type (e.g. library, project, metapackage, composer-plugin) []: library

// 6. 输入授权类型
License []:

Define your dependencies.

// 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”: “guanguans/uploadfile”,
“description”: “一个通用文件上传包”,
“type”: “library”,
“require”: {
“php”: “>=5.4”
},
“require-dev”: {
“php”: “>=5.4”
},
“license”: “MIT”,
“authors”: [
{
“name”: “guanguans”,
“email”: “yzmguanguan@gmail.com”
}
],
“minimum-stability”: “dev”
}

// 9. 是否生成composer.json
Do you confirm generation [yes]? yes
三、添加自动加载
在上一步生成的composer.json中追加

“autoload”: {
“psr-4”: {
“Guanguans\”: “src/”
}
}
四、构建项目
4.1 新建uploadfile/src/UploadFile.php
├─uploadfile
│ ├─src
│ │ ├─UploadFile.php
│ └─composer.json

<?php /** * 通用文件上传类 * @author guanguans
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值