adhocore / phint
使用模板初始化具有合理默认值的新的 PHP 项目
Requires
- php: >=7.1
- adhocore/cli: ^0.8.1
- adhocore/json-comment: ^0.1
- crazyfactory/docblocks: ^2.2
- symfony/finder: ^3.3.0
- twig/twig: ^2.4.0
Requires (Dev)
- phpunit/phpunit: ^6.0
- dev-master
- 0.6.1
- 0.6.0
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-dependabot/composer/adhocore/json-comment-tw-0.1or-tw-1.0
- dev-dependabot/composer/adhocore/cli-tw-0.8.1or-tw-0.9.0
- dev-main
- dev-dependabot/composer/phpunit/phpunit-tw-6.0or-tw-7.0
- dev-develop
This package is auto-updated.
Last update: 2024-08-25 17:49:38 UTC
README
使用模板初始化具有合理默认值的新的 PHP 项目。它通过脚手架方式构建 PHP 库 &/或项目,以提高您的生产力和节省时间。
对于已经存在的项目,运行带有 --sync
标志的命令以添加缺失的内容,参见 phint init。
一旦您在 src/
或 lib/
中有了文件,您就可以运行 phint docs 以生成类似 API 的文档(.md
格式),以及运行 phint test 以生成带有所有已维护结构的测试存根。
它可以帮助您变得更加懒惰!phint 正在不断发展,目标是使其变得更加庞大。
安装 · 功能 · 自动完成 · 用法 · phint init · phint update · phint docs · phint test · 模板
Phint 由 adhocore/cli 驱动
安装
需要 PHP7。
手册
从 最新版本 下载 phint.phar
。然后像这样使用它:php /path/to/phint.phar [opts] [args]
。嗯,不是很酷。请参阅下面的命令部分。
命令
# get latest version (you need `jq`) LATEST_PHINT=`curl --silent "https://api.github.com/repos/adhocore/phint/releases/latest" | jq -r .tag_name` # download latest phint curl -sSLo ~/phint.phar "https://github.com/adhocore/phint/releases/download/$LATEST_PHINT/phint.phar" # make executable chmod +x ~/phint.phar sudo ln -s ~/phint.phar /usr/local/bin/phint # check phint --help
功能
- 生成诸如
.gitignore, .travis.yml, .editorconfig
等类似 dot 文件 - 生成
LICENSE
、README.md
、composer.json
- 生成
CHANGELOG.md
草稿、CONTRIBUTING.md
指南、ISSUE_TEMPLATE.md
和PULL_REQUEST_TEMPLATE.md
- 如果有的话,生成二进制文件
- git init
- 交互式询问并安装所有开发和生产依赖项
- 生成
phpunit.xml
、测试bootstrap.php
- 为
src
中对应的所有类/方法生成测试存根(phint test
) - 为所有公共类/方法生成文档
- 将模板导出到指定的路径,以便可以进行自定义(
phint export
) - 从用户指定的路径使用自定义模板
- 更新自身(
phint update
)
自动完成
如果您使用 zsh shell 且已安装 oh-my-zsh,则 phint 命令和选项可以 自动完成。
设置自动完成
mkdir -p ~/.oh-my-zsh/custom/plugins/ahccli && cd ~/.oh-my-zsh/custom/plugins/ahccli [ -f ./ahccli.plugin.zsh ] || curl -sSLo ./ahccli.plugin.zsh https://raw.githubusercontent.com/adhocore/php-cli/master/ahccli.plugin.zsh echo compdef _ahccli phint >> ./ahccli.plugin.zsh chmod +x ./ahccli.plugin.zsh && source ./ahccli.plugin.zsh && cd -
不要忘记在 ~/.zshrc
文件的 plugins=(... ...)
列表中 添加 ahccli
。
用法
它可以快速生成包含所有基本和默认内容的新的项目。以下是快速步骤:
# See options/arguments phint init --help # OR (shortcut) phint i -h # Below command inits a brand new PHP project in `project-name` folder in current dir # Missing arguments are interactively collected phint init project-name # You can also use config file (with json) to read option values from phint init project-name --config phint.json
命令
以下每个命令应如此使用
cd /path/to/project phint <command> [--options] [args]
init
别名 i
创建和脚手架一个新的 PHP 项目。
参数
不要被长长的参数列表吓倒,您不需要将它们作为参数输入,因为它们在需要时会被交互式收集。
请检查配置,了解如何创建可重用的json配置,这样您就可以像专业人士一样使用phint
。
Arguments:
<project> The project name without slashes
Options:
[-b, --bin...] Executable binaries
[-c, --no-codecov] Disable codecov
[-C, --config] JSON filepath to read config from
[-d, --descr] Project description
[-D, --dev...] Developer packages
[-e, --email] Vendor email
[-f, --force] Run even if the project exists
[-G, --gh-template] Use `.github/` as template path
By default uses `docs/`
[-h, --help] Show help
[-w, --keywords...] Project Keywords
[-L, --license] License (m: MIT, g: GNULGPL, a: Apache2, b: BSDSimple, i: ISC, w: WTFPL)
[-n, --name] Vendor full name
[-N, --namespace] Root namespace (use `/` separator)
[-g, --package] Packagist name (Without vendor handle)
[-p, --path] The project path (Auto resolved)
[-P, --php] Minimum PHP version
[-R, --req...] Required packages
[-s, --no-scrutinizer] Disable scrutinizer
[-l, --no-styleci] Disable StyleCI
[-S, --sync] Only create missing files
Use with caution, take backup if needed
[-t, --no-travis] Disable travis
[-T, --type] Project type
[-u, --username] Vendor handle/username
[-z, --using] Reference package
[-y, --year] License Year
Usage Examples:
phint init <project> --force --descr "Awesome project" --name "YourName" --email you@domain.com
phint init <project> --using laravel/lumen --namespace Project/Api --type project</comment>
phint init <project> --php 7.0 --config /path/to/json --dev mockery/mockery --req adhocore/cli
示例配置
通过命令行参数发送的参数将比配置文件中的值(-C --config
)具有更高的优先级。
您可以在配置文件中放置什么内容?任何内容都可以,但我们建议您只放置已知选项(检查$ phint init --help
)
{ "type": "library", "namespace": "Ahc", "username": "adhocore", "name": "Jitendra Adhikari", "email": "jiten.adhikary@gmail.com", "php": "7.0", "codecov": false, "...": "..." }
更新
别名:u
更新Phint到最新版本或回滚到本地安装的早期版本。
参数
Options:
[-h, --help] Show help
[-r, --rollback] Rollback to earlier version
Usage Examples:
phint update Updates to latest version
phint u Also updates to latest version
phint update -r Rolls back to prev version
phint u --rollback Also rolls back to prev version
文档
别名:d
从它们的docblocks生成所有公共类和方法的文档(.md
)。
理想情况下,您应该在现有项目上或在创建/更新src/
文件后运行它。
参数
Options:
[-a, --with-abstract] Create docs for abstract/interface class
[-h, --help] Show help
[-o, --output] Output file (default README.md). For old project you should use something else
(OR mark region with <!-- DOCS START --> and <!-- DOCS END --> to inject docs)
Usage Examples:
phint docs If there is `<!-- DOCS START -->` and `<!-- DOCS END -->` region
Injects new doc in between them otherwise appends to bottom
phint d -o docs/api.md Writes to docs/api.md (Same rule applies regarding inject/append)
示例文档
PHP代码
namespace Abc; /** * This is dummy class. * * It does nothing as of now. * Maybe you could fix it? */ class Dummy { /** * Alpha beta. * * Example: * * <code> * $dummy = new Dummy; * $dummy->alpha('john', true); * // '...' * </code> * * @param string $name * @param bool $flag * * @return string|null */ public function alpha($name, $flag) { // } }
生成的Markdown
## Dummy ```php use Abc\Dummy; \``` > This is dummy class. It does nothing as of now. Maybe you could fix it? ### alpha() > Alpha beta. ```php alpha(string $name, bool $flag): string|null \``` Example: ```php $dummy = new Dummy; $dummy->alpha('john', true); // '...' \```
预览
占位符
use Ahc\Dummy;
这是一个占位符类。
目前它没有任何作用。也许您可以修复它?
alpha()
Alpha beta。
alpha(string $name, bool $flag): string|null
示例
$dummy = new Dummy; $dummy->alpha('john', true); // '...'
测试
别名:t
生成具有与源代码类似类和测试方法的测试文件。如果已经存在测试类,则跳过。将来我们可能会为新方法添加测试存根。
理想情况下,您应该在现有项目上或在创建/更新src/
文件后运行它。
参数
Options:
[-a, --with-abstract] Create stub for abstract/interface class
[-h, --help] Show help
[-n, --naming] Test method naming format
(t: testMethod | m: test_method | i: it_tests_)
[-p, --phpunit] Base PHPUnit class to extend from
[-s, --no-setup] Dont add setup method
[-t, --no-teardown] Dont add teardown method
Usage Examples:
phint test -n i With `it_` naming
phint t --no-teardown Without `tearDown()`
phint test -a With stubs for abstract/interface
示例测试
为上面的Abc\Dummy生成了tests/Dummy.php
<?php namespace Abc\Test; use Abc\Dummy; use PHPUnit\Framework\TestCase as TestCase; /** * Auto generated by `phint test`. */ class DummyTest extends TestCase { /** * @var Dummy */ protected $dummy; public function setUp() { parent::setUp(); $this->dummy = new Dummy; } public function testAlpha() { $actual = $this->dummy->alpha(); // $this->assertSame('', $actual); } }
模板化
phint export --to ~/myphint
所以您想要有自己的模板,并根据您的喜好定制phint
!
首先,您需要创建一个根目录(可以是任何名称,例如:myphint
),其结构如下所示
myphint
├── CHANGELOG.md.twig
├── composer.json.twig
├── CONTRIBUTING.md.twig
├── docs
│ ├── docs.twig
│ ├── ISSUE_TEMPLATE.md.twig
│ └── PULL_REQUEST_TEMPLATE.md.twig
├── .editorconfig.twig
├── .env.example.twig
├── .gitignore.twig
├── LICENSE.twig
├── package.json.twig
├── phpunit.xml.dist.twig
├── README.md.twig
├── tests
│ ├── bootstrap.php.twig
│ └── test.twig
└── .travis.yml.twig
请注意,您不需要在新目录中拥有所有文件,只需选择您想要定制的文件并开始修改即可。
幸运的是,您实际上不必自己创建这些模板,只需运行phint export --to ~/myphint
即可!
专业提示只要它们的扩展名是.twig
,您实际上可以引入任何新的模板。此类模板仅由phint init
命令使用。请检查模板变量。
在您完成这些模板的定制后,您可以在每个phint命令中使用它们,如下所示
phint init project --template ~/myphint phint docs --template ~/myphint phint test --template ~/myphint
--template
的简写选项是-x
。
模板变量
以下是这些模板在运行时将接收的参数
- docs/docs.twig:类元数据和文档参数
- tests/test.twig:类元数据和测试参数
- 其他所有内容:初始化参数
元数据
- “docs”和“test”命令读取和使用源文件元数据。
- “docs.twig”模板一次接收所有类的元数据集合。
- “test.twig”模板一次接收一个类的元数据单元。
类元数据
上面Abc\Dummy的示例元数据
[ 'namespace' => 'Abc', 'classFqcn' => 'Abc\\Dummy', 'classPath' => '/home/user/projects/src/Dummy.php', 'name' => 'Dummy', 'className' => 'Dummy', 'isTrait' => false, 'isAbstract' => false, 'isInterface' => false, 'newable' => true, 'title' => 'This is dummy class.', 'texts' => [ 'It does nothing as of now.', 'Maybe you could fix it?', ], 'methods' => [ 'alpha' => [ 'name' => 'alpha', 'inClass' => 'Abc\\Dummy', 'isStatic' => false, 'isFinal' => false, 'isPublic' => true, 'isAbstract' => false, 'maybeMagic' => false, 'title' => 'Alpha beta.', 'texts' => [ 'Example:', '<code>', '$dummy = new Dummy;', '$dummy->alpha(\'john\', true);', '// \'...\'', '</code>', ], 'return' => 'string|null', 'params' => [ 'string $name', 'bool $flag', ], ], // more methods ... ], ];
待办事项
包括但不限于
- README.md/文档生成器
- 测试文件生成器
- 支持用户模板
- 新方法的测试存根
许可证
© 2017-2020,Jitendra Adhikari | MIT
鸣谢
此库的发布由please管理。