conquerorsoft / my_first_library
这是我使用 composer init 创建的第一个库
Requires
- php: ~5.6 || ~7.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: 3.*
README
这是我第一次在 php[world] 上创建的库。我了解到我需要创建一个 README 文件来描述我的库,以便其他项目或人员使用。
创建 "我的第一个库" 的步骤
1- 创建 my_first_library 目录
cd ~ && mkdir -p phplibrary/my_first_library && cd phplibrary/my_first_library
2- 创建 README.md 文件
vim README.md
3- 初始化 git 仓库
git init
4- 执行第一次提交
git add .
git commit -m "First commit of my library"
5- 为你的库分配一个版本号
git tag -a v0.1.0 -m "version 0.1.0"
6- 在 github 或 bitbucket 上创建仓库 7- 将你的仓库连接到 github (或 bitbucket)
git remote add origin https://github.com/ConquerorSoft/my_first_library.git
git push -u origin master
git push origin v0.1.0
8- 运行 composer init
composer init
9- 输入 composer init 询问的所有信息
Package name (<vendor>/<name>) [gabriel/my_first_library]: conquerorsoft/my_first_library
Description []: This is my very first library created with composer init
Author [Christian Varela <dobleclick.mx@gmail.com>, n to skip]: Christian Varela <cvarela@conquerorsoft.com>
Minimum Stability []: stable
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]?
Search for a package: phpunit
Found 15 packages matching phpunit
[0] phpunit/phpunit
[1] mockery/mockery
[2] phpunit/phpunit-mock-objects
[3] phpunit/php-timer
[4] phpunit/php-code-coverage
[5] phpunit/phpunit-selenium
[6] brianium/paratest
[7] phpunit/php-token-stream
[8] phpunit/php-text-template
[9] phpunit/php-file-iterator
[10] mybuilder/phpunit-accelerator
[11] johnkary/phpunit-speedtrap
[12] symfony/phpunit-bridge
[13] nette/tester
[14] gecko-packages/gecko-php-unit
Enter package # to add, or the complete package name if it is not listed: 0
Enter the version constraint to require (or leave blank to use the latest version): ^5.7
Using version ^5.7 for phpunit/phpunit
Search for a package:
{
"name": "conquerorsoft/my_first_library",
"description": "This is my very first library created with composer init",
"type": "library",
"require-dev": {
"phpunit/phpunit": "^5.7"
},
"license": "MIT",
"authors": [
{
"name": "Christian Varela",
"email": "cvarela@conquerorsoft.com"
}
],
"minimum-stability": "stable",
"require": {}
}
Do you confirm generation [yes]?
Would you like the vendor directory added to your .gitignore [yes]?
10- 创建 composer.json 文件,提交到 git
git add .
git commit -m "Composer init"
git tag -a v0.1.1 -m "version 0.1.1"
git push -u origin master
git push origin v0.1.1
11- 运行 composer install
composer install
12- 将 composer.lock 添加到 .gitignore
echo "composer.lock" >> .gitignore
13- 创建 Changelog 文件(推荐格式:[Keep a Changelog](http://keepachangelog.com/en/1.0.0/))
vim CHANGELOG.md
14- 提交到 git
git add .
git commit -m "Changelog file added"
git tag -a v0.1.2 -m "version 0.1.2"
git push -u origin master
git push origin v0.1.2
15- 创建开始开发的结构
mkdir src && mkdir tests
16- 编辑 composer.json 文件,使其现在看起来是这样的
{
"name": "conquerorsoft/my_first_library",
"description": "This is my very first library created with composer init",
"keywords": [
"conquerorsoft",
"my_first_library",
"tutorial",
"phpworld 2017",
"workshop"
],
"homepage": "http://www.conquerorsoft.com/my_first_library",
"type": "library",
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "3.*"
},
"license": "MIT",
"authors": [
{
"name": "Christian Varela",
"email": "cvarela@conquerorsoft.com",
"homepage": "http://www.conquerorsoft.com/ChristianVarela",
"role": "Developer"
}
],
"minimum-stability": "stable",
"require": {
"php": "~5.6 || ~7.0"
},
"autoload": {
"psr-4": {
"conquerorsoft\\my_first_library\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"conquerorsoft\\my_first_library\\": "tests"
}
},
"scripts": {
"test": "phpunit",
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
}
}
17- 创建 phpunit.xml 文件
vim phpunit.xml
18- 将 build 添加到 .gitignore
echo build >> .gitignore
19- 运行 composer update
composer update
20- 提交到 git
git add .
git commit -m "Preparation for development"
git tag -a v0.1.3 -m "version 0.1.3"
git push -u origin master
git push origin v0.1.3
21- 添加 LICENSE.md 文件(本例中我们选择 MIT)
vim LICENSE.md
22- 创建 tests/FirstClassTest.php
vim tests/FirstClassTest.php
23- 创建 src/FirstClass.php
vim src/FirstClass.php
24- 提交到 git
git add .
git commit -m "Encode and decode string functionality"
git tag -a v0.1.4 -m "version 0.1.4"
git push -u origin master
git push origin v0.1.4
25- 对所有类、文件和函数进行 docblock
/**
* This is a summary example
*
* This is a description
*
* @example this is tag
*/
26- 提交到 git
git add .
git commit -m "Docblocks added everywhere"
git tag -a v0.1.5 -m "version 0.1.5"
git push -u origin master
git push origin v0.1.5
27- 将仓库添加到 Travis 并创建 Travis 配置文件
vim .travis.yml
28- 提交到 git
git add .
git commit -m "Travis CI integration"
git tag -a v0.1.6 -m "version 0.1.6"
git push -u origin master
git push origin v0.1.6
29- 将 composer.json 中的 phpunit 版本更改为 ^5.7
vim composer.json
30- 提交到 git
git add .
git commit -m "Phpunit version changed to support php version 5.6"
git tag -a v0.1.7 -m "version 0.1.7"
git push -u origin master
git push origin v0.1.7
31- 获取 Travis 徽章并将其放入 README 文件中
vim README.md
32- 在 README 文件中放置许可证徽章 33- 提交到 git
git add .
git commit -m "Travis CI and License badges in README"
git tag -a v0.1.8 -m "version 0.1.8"
git push -u origin master
git push origin v0.1.8
34- 创建 scrutinizer-ci 账户并将其与 github 链接 35- 创建 .scrutinizer.yml 文件
vim .scrutinizer.yml
36- 在 README 文件中获取 scrutinizer 徽章
vim README.md
37- 提交到 git
git add .
git commit -m "Scrutinizer CI and badges in README"
git tag -a v0.1.9 -m "version 0.1.9"
git push -u origin master
git push origin v0.1.9
38- 删除与 php 5.6 不兼容的类型提示
vim FirstClass.php
39- 提交到 git
git add .
git commit -m "Fixes to uncompatible type hinting"
git tag -a v0.1.10 -m "version 0.1.10"
git push -u origin master
git push origin v0.1.10
40- 从 scrutinizer 应用补丁 41- 提交到 git
git add .
git commit -m "Spacing patch from scrutinizer applied"
git tag -a v0.1.11 -m "version 0.1.11"
git push -u origin master
git push origin v0.1.11
42- 创建 Contributing 文件
vim CONTRIBUTING.md
vim CODE_OF_CONDUCT.md
43- 在 README 文件中添加更多部分
- 安装
- 用法
- 变更日志
- 测试
- 贡献
- 安全
- 鸣谢
- 许可证
44- 提交到 git
git add .
git commit -m "Improvements to README"
git tag -a v0.1.12 -m "version 0.1.12"
git push -u origin master
git push origin v0.1.12
45- 添加 .gitattributes 文件以在使用 --prefer-dist 时忽略某些文件或文件夹
vim .gitattributes
46- 提交到 git
git add .
git commit -m ".gitattributes file created"
git tag -a v0.1.13 -m "version 0.1.13"
git push -u origin master
git push origin v0.1.13
47- 在 packagist.org 上创建账户,并使用你的 github 仓库提交你的库 48- 让你的 packagist 包在推送时自动更新
- 转到你的 GitHub 仓库
- 点击 "设置" 按钮
- 点击 "集成与服务"
- 添加 "Packagist" 服务,并使用你的 API 令牌和 Packagist 用户名进行配置
- 勾选 "活动" 复选框并提交表单
49- 在 README.md 文件中添加 Packagist 徽章的最新版本
vim README.md
50- 提交到 git
git add .
git commit -m "Instructions to use packagist.org in README"
git tag -a v0.1.14 -m "version 0.1.14"
git push -u origin master
git push origin v0.1.14
51- 创建 gh-pages 分支
git checkout -b gh-pages
git push -u origin gh-pages
git checkout master
52- 转到你的仓库的 github 设置 53- 在 GitHub Pages 部分选择一个主题 54- 你的库页面现在准备好了:[https://conquerorsoft.github.io/my_first_library/](https://conquerorsoft.github.io/my_first_library/) 55- 提交到 git 并增加版本
git add .
git commit -m "Documentation instructions for the library"
git tag -a v1.0.0 -m "version 1.0.0"
git push -u origin master
git push origin v1.0.0
安装
使用 composer
composer require conquerorsoft/my_first_library
用法
$my_first_library = new conquerorsoft\my_first_library\FirstClass();
$encoded_string = $my_first_library->encodeString("Encoding this string");
$decode_string = $my_first_library->decodeString("03wwrwp o0xv v7 or012 y0xsnl2");
变更日志
请参阅变更日志获取有关最近更改的更多信息。
测试
composer test
贡献
安全
如果您发现任何与安全相关的问题,请通过电子邮件cvarela@conquerorsoft.com联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可(MIT)。请参阅许可文件以获取更多信息。