topphp/component-builder

组件生成器

dev-master / 1.0.0.x-dev 2020-03-12 17:26 UTC

This package is auto-updated.

Last update: 2024-09-13 03:43:11 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

前言 为了让开发者更好地为 topphp 开发组件,我们提供了本指南用于指导开发者进行组件开发,在阅读本指南前,需要您对 topphp 和 thinkphp 的文档进行仔细的阅读。

为什么要开发组件

在 PHP-FPM 架构下的开发,通常在我们需要借助第三方库来解决我们的需求时,都会通过 Composer 直接引入一个对应的组件,但是有时候第三方库并不能满足我们的需求时,会自己进行一个组件的封装。而且 topphp 可以在 swoole 环境下持久化运行,且支持协程,导致了第三方组件会存在一些使用上的问题。阅读本指南会教会你如何开发一个属于自己的 topphp 组件。

组件开发的环境及准备工作

1. 安装骨架项目 (topphp/topphp-skeleton)
git clone https://github.com/topphp/topphp-skeleton.git
2. 在同级目录下添加 topphp 文件夹
3. 进入 topphp 文件夹,并通过组件创建器 (topphp/component-builder) 进行组件创建
# 运行以下命令
$ cd topphp
$ composer create-project topphp/component-builder=dev-master 你的组件名字

composer create-project topphp/component-builder=dev-master topphp-testing
Installing topphp/component-builder (dev-master 63957ce7c3e9e8425c280c0fa4135e847a6d5ec3)
- Installing topphp/component-builder (dev-master 63957ce): Cloning 63957ce7c3 from cache
Created project in topphp-testing
> Topphp\Install\Shell::init
请对组件进行配置
请输入你的组件名称(topphp/demo):topphp/topphp-testing
填写你的组件描述:单元测试组件
请设置你的软件许可证(MIT):
请填写应用命名空间 (Topphp\TopphpTesting):
需要安装 topthink/framework 组件吗? [n]:y
正在删除安装脚本命名空间...
正在删除安装脚本相关composer配置...
删除安装脚本目录
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 29 installs, 0 updates, 0 removals
- Installing sebastian/version (2.0.1): Loading from cache
- Installing sebastian/resource-operations (2.0.1): Loading from cache
- Installing sebastian/recursion-context (3.0.0): Loading from cache
- Installing sebastian/object-reflector (1.1.1): Loading from cache
- Installing sebastian/object-enumerator (3.0.3): Loading from cache
- Installing sebastian/global-state (2.0.0): Loading from cache
- Installing sebastian/exporter (3.1.2): Loading from cache
- Installing sebastian/environment (4.2.3): Loading from cache
- Installing sebastian/diff (3.0.2): Loading from cache
- Installing sebastian/comparator (3.0.2): Loading from cache
- Installing phpunit/php-timer (2.1.2): Loading from cache
- Installing phpunit/php-text-template (1.2.1): Loading from cache
- Installing phpunit/php-file-iterator (2.0.2): Loading from cache
- Installing theseer/tokenizer (1.1.3): Loading from cache
- Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
- Installing phpunit/php-token-stream (3.1.1): Loading from cache
- Installing phpunit/php-code-coverage (6.1.4): Loading from cache
- Installing doctrine/instantiator (1.3.0): Loading from cache
- Installing symfony/polyfill-ctype (v1.13.1): Loading from cache
- Installing webmozart/assert (1.6.0): Loading from cache
- Installing phpdocumentor/reflection-common (2.0.0): Loading from cache
- Installing phpdocumentor/type-resolver (1.0.1): Loading from cache
- Installing phpdocumentor/reflection-docblock (5.0.0): Loading from cache
- Installing phpspec/prophecy (v1.10.2): Loading from cache
- Installing phar-io/version (2.0.1): Loading from cache
- Installing phar-io/manifest (1.0.3): Loading from cache
- Installing myclabs/deep-copy (1.9.5): Loading from cache
- Installing phpunit/phpunit (7.5.20): Loading from cache
- Installing squizlabs/php_codesniffer (3.5.4): Loading from cache
sebastian/global-state suggests installing ext-uopz (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
phpunit/phpunit suggests installing ext-xdebug (*)
Writing lock file
Generating autoload files
Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]? Y
4. 这样做的目的是为了让 topphp-skeleton 项目可以直接通过 path 的形式,让 Composer 直接通过 topphp 文件夹内的项目作为依赖项被加载到 topphp-skelton 项目的 vendor 目录中,我们对 topphp-skelton 内的 composer.json 文件增加一个 repositories 项,如下:
{
    "repositories": {
        "hyperf": {
            "type": "path",
            "url": "../topphp/*"
        },
        "packagist": {
            "type": "composer",
            "url": "https://mirrors.aliyun.com/composer"
        }
    }
}
5. 然后删除 topphp-skeleton 项目内的 composer.lock 文件和 vendor 目录,再执行 composer require 你刚刚安装的组件=dev-master,或者直接在 composer.json 增加如下代码
{
   "require":{
      "你的组件名字": "dev-master"
  }
}

然后就可以对组件进行开发了。

注意

交互输入必须使用英文半角输入法,否则会出现字符确实。

现代的 PHP 组件都使用语义版本方案 (http://semver.org),版本号由三个点(.)分数字组成(例如:1.13.2)。第一个数字是主版本号,如果 PHP 组件更新破坏了向后兼容性,会提升主版本号。第二个数字是次版本号,如果 PHP 组件小幅更新了功能,而且没有破坏向后兼容性,会提升次版本号。第三个数字(即最后一个数字)是修订版本号,如果 PHP 组件修正了向后兼容的缺陷,会提升修订版本号。

结构

组件结构

bin/        
build/
docs/
config/
src/
tests/
vendor/

安装

通过 Composer

$ composer create-project topphp/component-builder 你的组件名称

使用

$skeleton = new topphp\componentBuilder();
echo $skeleton->echoPhrase('Hello, TOPPHP!');

变更日志

请参阅 CHANGELOG 了解最近的变化。

测试

$ composer test

贡献

请参阅 CONTRIBUTINGCODE_OF_CONDUCT 了解详细信息。

安全

如果你发现任何安全问题,请通过电子邮件 sleep@kaituocn.com 而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。