From 9db3de075fbb74888c629871ecf080aa83083cf0 Mon Sep 17 00:00:00 2001 From: Yurun Date: Mon, 23 Oct 2023 15:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=BC=83=20Hprose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/php.dockerfile | 1 - .github/script/hprose.sh | 8 - .github/swoole.dockerfile | 1 - .php-cs-fixer.php | 1 - README.md | 2 +- doc/README.md | 2 +- doc/SUMMARY.md | 2 - doc/base/version/2.1-3.0.md | 4 + doc/components/list.md | 1 - doc/components/rpc/hprose.md | 170 ----------- split-repository/release.php | 3 - split-repository/split.php | 3 - src/Components/hprose/.gitattributes | 9 - .../hprose/.github/workflows/pr.yml | 13 - src/Components/hprose/.gitignore | 2 - src/Components/hprose/LICENSE | 87 ------ src/Components/hprose/README.md | 206 -------------- src/Components/hprose/composer.json | 36 --- src/Components/hprose/dev/Dev.php | 77 ----- src/Components/hprose/rector.php | 5 - .../hprose/src/Client/HproseService.php | 64 ----- .../hprose/src/Client/HproseSocketClient.php | 95 ------- .../hprose/src/Imi-Server-Hprose/Server.php | 264 ------------------ .../hprose/src/Listener/AddRouteRule.php | 62 ---- .../hprose/src/Listener/InitDefaultRoute.php | 37 --- src/Components/hprose/src/Main.php | 14 - .../src/Route/Annotation/HproseRoute.php | 33 --- src/Components/hprose/src/Route/Route.php | 87 ------ src/Components/hprose/src/config/config.php | 11 - src/Components/rpc/README.md | 2 - website/src/page/index.html | 1 - 31 files changed, 6 insertions(+), 1297 deletions(-) delete mode 100644 .github/script/hprose.sh delete mode 100644 doc/components/rpc/hprose.md delete mode 100644 src/Components/hprose/.gitattributes delete mode 100644 src/Components/hprose/.github/workflows/pr.yml delete mode 100644 src/Components/hprose/.gitignore delete mode 100644 src/Components/hprose/LICENSE delete mode 100644 src/Components/hprose/README.md delete mode 100644 src/Components/hprose/composer.json delete mode 100644 src/Components/hprose/dev/Dev.php delete mode 100644 src/Components/hprose/rector.php delete mode 100644 src/Components/hprose/src/Client/HproseService.php delete mode 100644 src/Components/hprose/src/Client/HproseSocketClient.php delete mode 100644 src/Components/hprose/src/Imi-Server-Hprose/Server.php delete mode 100644 src/Components/hprose/src/Listener/AddRouteRule.php delete mode 100644 src/Components/hprose/src/Listener/InitDefaultRoute.php delete mode 100644 src/Components/hprose/src/Main.php delete mode 100644 src/Components/hprose/src/Route/Annotation/HproseRoute.php delete mode 100644 src/Components/hprose/src/Route/Route.php delete mode 100644 src/Components/hprose/src/config/config.php diff --git a/.github/php.dockerfile b/.github/php.dockerfile index 39670699f9..cc280ffd6f 100644 --- a/.github/php.dockerfile +++ b/.github/php.dockerfile @@ -20,5 +20,4 @@ RUN set -eux \ && curl -sfL https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer && chmod +x /usr/bin/composer \ && curl -L -o swoole.tar.gz https://github.com/swoole/swoole-src/archive/${SWOOLE_VERSION}.tar.gz && mkdir -p swoole && tar -xzf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && ((stat ./make.sh && ./make.sh) || (stat ./scripts/make.sh && ./scripts/make.sh)) && cd - && docker-php-ext-enable swoole \ && bash /tmp/script/swoole_postgresql.sh ${POSTGRESQL_VERSION} \ - && bash /tmp/script/hprose.sh \ && echo "zend_extension=opcache.so" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini diff --git a/.github/script/hprose.sh b/.github/script/hprose.sh deleted file mode 100644 index 8b0f7a4896..0000000000 --- a/.github/script/hprose.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -ex - -if [ "$(php -r 'echo PHP_VERSION_ID < 80000 ? 1 : 0;')" = "1" ]; then - pecl install hprose - docker-php-ext-enable hprose -fi \ No newline at end of file diff --git a/.github/swoole.dockerfile b/.github/swoole.dockerfile index 292dbe266b..c1b598404f 100644 --- a/.github/swoole.dockerfile +++ b/.github/swoole.dockerfile @@ -17,5 +17,4 @@ RUN set -eux \ && pecl install apcu \ && docker-php-ext-enable apcu \ && bash /tmp/script/swoole_postgresql.sh ${POSTGRESQL_VERSION} \ - && bash /tmp/script/hprose.sh \ && echo "zend_extension=opcache.so" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 257f6c4c75..b5cc0fa04f 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -133,7 +133,6 @@ PhpCsFixer\Finder::create() ->in(__DIR__) ->notPath('src/Components/swoole/src/Util/Coroutine.typed.php') // 兼容 Swoole 5.0,需要 PHP >= 8.0 - ->notPath('src/Components/hprose/src/Imi-Server-Hprose/Server.php') // bug: https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/6534 ->notPath('src/Components/grpc/example/grpc') ) ; diff --git a/README.md b/README.md index fef3140188..113d70e0ad 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ imi 是一款支持长连接微服务分布式的 PHP 开发框架,它可以运行在 `PHP-FPM`、`Swoole`、`Workerman` 和 `RoadRunner` 等多种容器环境下。 -imi 提供了丰富的基础功能:`MySQL`、`PostgreSQL`、`Redis`、`超强超好用的自研 ORM`、`连接池`、`Web Api`、`Web MVC`、`WebSocket`、`TCP Server`、`UDP Server`、`HTTP2`、`MQTT`、`gRPC`、`容器化(Container)`、`依赖注入`、`Aop`、`事件`、`异步(Async)`、`缓存(Cache)`、`命令行(Command)`、`配置化(Config)`、`上下文(Context)`、`定时任务(Cron)`、`门面(Facade)`、`验证器(Validate)`、`锁(Lock)`、`日志(Log)`、`定时器(Timer)`、`权限控制`、`消息队列(RabbitMQ、Kafka、Redis)`、`Swagger`、`Hprose`、`宏(Macro)`、`限流`、`共享内存`、`Smarty`、`雪花算法发号器(Snowflake)`、`Workerman Gateway`、`InfluxDB` 和 `TDengine` 等组件。 +imi 提供了丰富的基础功能:`MySQL`、`PostgreSQL`、`Redis`、`超强超好用的自研 ORM`、`连接池`、`Web Api`、`Web MVC`、`WebSocket`、`TCP Server`、`UDP Server`、`HTTP2`、`MQTT`、`gRPC`、`容器化(Container)`、`依赖注入`、`Aop`、`事件`、`异步(Async)`、`缓存(Cache)`、`命令行(Command)`、`配置化(Config)`、`上下文(Context)`、`定时任务(Cron)`、`门面(Facade)`、`验证器(Validate)`、`锁(Lock)`、`日志(Log)`、`定时器(Timer)`、`权限控制`、`消息队列(RabbitMQ、Kafka、Redis)`、`Swagger`、`宏(Macro)`、`限流`、`共享内存`、`Smarty`、`雪花算法发号器(Snowflake)`、`Workerman Gateway`、`InfluxDB` 和 `TDengine` 等组件。 同时,imi 还提供了微服务相关支持:`Nacos 配置中心`、`etcd 配置中心`、`Nacos 服务注册`、`Nacos 服务发现`、`Swoole Tracker`、`Zipkin`、`Jaeger`、`Prometheus`、`InfluxDB 服务指标监控`、`TDengine 服务指标监控` 和 `负载均衡` 等组件。 diff --git a/doc/README.md b/doc/README.md index 9abb57d6fe..d9a84efd7a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -8,7 +8,7 @@ imi 是一款支持长连接微服务分布式的 PHP 开发框架,可在 `PHP-FPM`、`Swoole`、`Workerman` 和 `RoadRunner` 等多种容器环境下运行。 -imi 提供了丰富的基础功能:`MySQL`、`PostgreSQL`、`Redis`、`超强超好用的自研 ORM`、`连接池`、`Web Api`、`Web MVC`、`WebSocket`、`TCP Server`、`UDP Server`、`HTTP2`、`MQTT`、`gRPC`、`容器化(Container)`、`依赖注入`、`Aop`、`事件`、`异步(Async)`、`缓存(Cache)`、`命令行(Command)`、`配置化(Config)`、`上下文(Context)`、`定时任务(Cron)`、`门面(Facade)`、`验证器(Validate)`、`锁(Lock)`、`日志(Log)`、`定时器(Timer)`、`权限控制`、`消息队列(RabbitMQ、Kafka、Redis)`、`Swagger`、`Hprose`、`宏(Macro)`、`限流`、`共享内存`、`Smarty`、`雪花算法发号器(Snowflake)`、`Workerman Gateway`、`InfluxDB` 和 `TDengine` 等组件。 +imi 提供了丰富的基础功能:`MySQL`、`PostgreSQL`、`Redis`、`超强超好用的自研 ORM`、`连接池`、`Web Api`、`Web MVC`、`WebSocket`、`TCP Server`、`UDP Server`、`HTTP2`、`MQTT`、`gRPC`、`容器化(Container)`、`依赖注入`、`Aop`、`事件`、`异步(Async)`、`缓存(Cache)`、`命令行(Command)`、`配置化(Config)`、`上下文(Context)`、`定时任务(Cron)`、`门面(Facade)`、`验证器(Validate)`、`锁(Lock)`、`日志(Log)`、`定时器(Timer)`、`权限控制`、`消息队列(RabbitMQ、Kafka、Redis)`、`Swagger`、`宏(Macro)`、`限流`、`共享内存`、`Smarty`、`雪花算法发号器(Snowflake)`、`Workerman Gateway`、`InfluxDB` 和 `TDengine` 等组件。 同时,imi 还提供了微服务相关支持:`Nacos 配置中心`、`etcd 配置中心`、`Nacos 服务注册`、`Nacos 服务发现`、`Swoole Tracker`、`Zipkin`、`Jaeger`、`Prometheus`、`InfluxDB 服务指标监控`、`TDengine 服务指标监控` 和 `负载均衡` 等组件。 diff --git a/doc/SUMMARY.md b/doc/SUMMARY.md index e2924882a8..6415419507 100644 --- a/doc/SUMMARY.md +++ b/doc/SUMMARY.md @@ -141,7 +141,6 @@ ## RPC 服务 -* [Hprose](components/rpc/hprose.md) * [gRPC](components/rpc/grpc.md) * [gRPC 服务开发](components/rpc/grpc.md) * [Protobuf](components/rpc/grpc-protobuf.md) @@ -215,7 +214,6 @@ * [PostgreSQL](components/db/pgsql.md) * [MQTT](components/mqtt/server.md) * [gRPC](components/rpc/grpc.md) - * [Hprose](components/rpc/hprose.md) * [消息队列](components/mq/redis.md) * [AMQP](components/mq/amqp.md) * [Kafka](components/mq/kafka.md) diff --git a/doc/base/version/2.1-3.0.md b/doc/base/version/2.1-3.0.md index 63bd07de04..8a8ee3cb82 100644 --- a/doc/base/version/2.1-3.0.md +++ b/doc/base/version/2.1-3.0.md @@ -24,6 +24,10 @@ 废弃并移出主仓库,代码仓库: +### imi-hprose + +由于 Hprose 官方弃坑,废弃并移出主仓库,代码仓库: + ### 废弃 * 废弃命名空间声明在 `config.php` 的写法,统一写到 `composer.json` 的 `imi.namespace` diff --git a/doc/components/list.md b/doc/components/list.md index 4b48704d9d..93d4938b8c 100644 --- a/doc/components/list.md +++ b/doc/components/list.md @@ -8,7 +8,6 @@ * [MQTT](/components/mqtt/server.html) * [RPC](https://github.com/imiphp/imi-rpc) * [gRPC](/components/rpc/grpc.html) -* [Hprose](/components/rpc/hprose.html) * [消息队列](/components/mq/redis.html) * [AMQP](/components/mq/amqp.html) * [Kafka](/components/mq/kafka.html) diff --git a/doc/components/rpc/hprose.md b/doc/components/rpc/hprose.md deleted file mode 100644 index d4d1dd4836..0000000000 --- a/doc/components/rpc/hprose.md +++ /dev/null @@ -1,170 +0,0 @@ -# Hprose - -[toc] - -## 介绍 - -在 imi 框架中集成 Hprose 服务开发,目前支持`TCP`、`Unix Socket`协议。 - -Github: - -> 仅支持 Swoole - -## Composer - -本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 `composer.json` 中加入下面的内容: - -```json -{ - "require": { - "imiphp/imi-hprose": "~3.0.0" - } -} -``` - -然后执行 `composer update` 安装。 - -## 服务端 - -在项目 `config/config.php` 中配置: - -```php -[ - 'components' => [ - // 引入RPC组件以及本组件 - 'Rpc' => 'Imi\Rpc', - 'Hprose' => 'Imi\Hprose', - ], -] -``` - -如果你用主服务器: - -```php -[ - // 主服务器配置 - 'mainServer' => [ - 'namespace' => 'XXX\MainServer', // 你的命名空间 - 'type' => 'Hprose', // 必须设为 Hprose - 'port' => 8080, - ], -] -``` - -如果你用子服务器: - -```php -[ - // 子服务器(端口监听)配置 - 'subServers' => [ - // 子服务器名 - 'XXX' => [ - 'namespace' => 'XXX\Hprose', // 你的命名空间 - 'type' => 'Hprose', // 必须设为 Hprose - 'port' => 50001, - ] - ], -] -``` - -### 控制器基类 - -`Imi\Rpc\Controller\RpcController` - -### 控制器注解 - -`\Imi\Rpc\Route\Annotation\RpcController` - -用法: - -`@RpcController` - -别名前缀:`@RpcController("a_b_")` - -指定服务器:`@RpcController(prefix="a_b_", server="服务器名")` - -### 动作注解 - -`\Imi\Rpc\Route\Annotation\RpcAction` - -无参 - -### 路由注解 - -`\Imi\Hprose\Route\Annotation\HproseRoute` - -参数: - -- `name` 路由名称规则。一般也是方法名,如果设置了别名,则最终为别名+方法名 -- `mode` 该设置表示该服务函数返回的结果类型,具体值请参考 Hprose 文档 -- `simple` 该设置表示本服务函数所返回的结果是否为简单数据。默认值为 false。 -- `oneway` 该设置表示本服务函数是否不需要等待返回值。当该设置为 true 时,调用会异步开始,并且不等待结果,立即返回 null 给客户端。默认值为 false。 -- `async` 该设置表示本服务函数是否为异步函数,异步函数的最后一个参数是一个回调函数,用户需要在异步函数中调用该回调方法来传回返回值 -- `passContext` 该属性为 boolean 类型,默认值为 false。具体请参考 Hprose 文档 - -> Hprose 文档参考: - -## 客户端 - -### 连接池配置 - -```php -[ - 'pools' => [ - '连接池名' => [ - 'pool' => [ - 'class' => \Imi\Rpc\Client\Pool\RpcClientCoroutinePool::class, - 'config' => [ - // 连接池通用,查阅文档 - ], - ], - 'resource' => [ - 'clientClass' => \Imi\Hprose\Client\HproseSocketClient::class, - 'uris' => 'tcp://127.0.0.1:50001', // 连接地址 - // 其它配置 - ] - ], - ], - 'rpc' => [ - 'defaultPool' => '连接池名', // 默认连接池名 - ], -] -``` - -### 客户端调用 - -代码调用: - -```php -\Imi\Rpc\Client\Pool\RpcClientPool::getService('服务名')->方法名(参数); -``` - -注解调用: - -```php -class Test -{ - /** - * @RpcClient() - * - * @var \Imi\Rpc\Client\IRpcClient - */ - protected $rpcClient; - - /** - * @RpcService(serviceName="服务名") - * - * @var \Imi\Rpc\Client\IService - */ - protected $xxxRpc; - - public function aaa() - { - // 方法一 - $this->rpcClient->getService('服务名')->方法名(参数); - - // 方法二 - $this->xxxRpc->方法名(参数); - } -} -``` diff --git a/split-repository/release.php b/split-repository/release.php index f84041eaae..5c2a7d6108 100644 --- a/split-repository/release.php +++ b/split-repository/release.php @@ -128,9 +128,6 @@ function getBranch(): string 'src/Components/grpc' => [ 'git@github.com:imiphp/imi-grpc', ], - 'src/Components/hprose' => [ - 'git@github.com:imiphp/imi-hprose', - ], 'src/Components/jwt' => [ 'git@github.com:imiphp/imi-jwt', ], diff --git a/split-repository/split.php b/split-repository/split.php index 26c712ddd4..1ce300c5c2 100644 --- a/split-repository/split.php +++ b/split-repository/split.php @@ -147,9 +147,6 @@ function saveConfig(): void 'src/Components/grpc' => [ 'git@github.com:imiphp/imi-grpc', ], - 'src/Components/hprose' => [ - 'git@github.com:imiphp/imi-hprose', - ], 'src/Components/jwt' => [ 'git@github.com:imiphp/imi-jwt', ], diff --git a/src/Components/hprose/.gitattributes b/src/Components/hprose/.gitattributes deleted file mode 100644 index f2ccdc87f2..0000000000 --- a/src/Components/hprose/.gitattributes +++ /dev/null @@ -1,9 +0,0 @@ -* text=auto - -/.gitattributes export-ignore -/.gitignore export-ignore -/.github export-ignore -/res export-ignore -/tests export-ignore -/dev export-ignore -/bin export-ignore diff --git a/src/Components/hprose/.github/workflows/pr.yml b/src/Components/hprose/.github/workflows/pr.yml deleted file mode 100644 index 230dacc658..0000000000 --- a/src/Components/hprose/.github/workflows/pr.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "首先非常感谢您的 PR,但本仓库不支持提交 PR,请到主仓库提交:https://github.com/imiphp/imi" diff --git a/src/Components/hprose/.gitignore b/src/Components/hprose/.gitignore deleted file mode 100644 index de4a392c33..0000000000 --- a/src/Components/hprose/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/vendor -/composer.lock diff --git a/src/Components/hprose/LICENSE b/src/Components/hprose/LICENSE deleted file mode 100644 index 48b721c4e3..0000000000 --- a/src/Components/hprose/LICENSE +++ /dev/null @@ -1,87 +0,0 @@ -木兰宽松许可证, 第2版 - -2020年1月 http://license.coscl.org.cn/MulanPSL2 - -您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: - -0. 定义 - -“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 - -“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 - -“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 - -“法人实体” 是指提交贡献的机构及其“关联实体”。 - -“关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 - -1. 授予版权许可 - -每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 - -2. 授予专利许可 - -每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 - -3. 无商标许可 - -“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 - -4. 分发限制 - -您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 - -5. 免责声明与责任限制 - -“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 - -6. 语言 - -“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 - -条款结束 - -Mulan Permissive Software License,Version 2 (Mulan PSL v2) - -January 2020 http://license.coscl.org.cn/MulanPSL2 - -Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: - -0. Definition - -Software means the program and related documents which are licensed under this License and comprise all Contribution(s). - -Contribution means the copyrightable work licensed by a particular Contributor under this License. - -Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. - -Legal Entity means the entity making a Contribution and all its Affiliates. - -Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. - -1. Grant of Copyright License - -Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. - -2. Grant of Patent License - -Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. - -3. No Trademark License - -No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4. - -4. Distribution Restriction - -You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. - -5. Disclaimer of Warranty and Limitation of Liability - -THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -6. Language - -THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. - -END OF THE TERMS AND CONDITIONS \ No newline at end of file diff --git a/src/Components/hprose/README.md b/src/Components/hprose/README.md deleted file mode 100644 index 84ea6315b4..0000000000 --- a/src/Components/hprose/README.md +++ /dev/null @@ -1,206 +0,0 @@ -# imi-hprose - -[![Latest Version](https://img.shields.io/packagist/v/imiphp/imi-hprose.svg)](https://packagist.org/packages/imiphp/imi-hprose) -[![Php Version](https://img.shields.io/badge/php-%3E=8.1-brightgreen.svg)](https://secure.php.net/) -[![Swoole Version](https://img.shields.io/badge/swoole-%3E=4.1.0-brightgreen.svg)](https://github.com/swoole/swoole-src) -[![IMI License](https://img.shields.io/github/license/imiphp/imi-hprose.svg)](https://github.com/imiphp/imi-hprose/blob/master/LICENSE) - -## 介绍 - -在 imi 框架中集成 Hprose 服务开发,目前支持`TCP`、`Unix Socket`协议。 - -未来将实现:中间件、过滤器、`Http` 协议、`WebSocket` 协议…… - -> 本仓库仅用于浏览,不接受 issue 和 Pull Requests,请前往: - -## Composer - -本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 `composer.json` 中加入下面的内容: - -```json -{ - "require": { - "imiphp/imi-hprose": "~3.0.0" - } -} -``` - -然后执行 `composer update` 安装。 - -## 服务端 - -在项目 `config/config.php` 中配置: - -```php -[ - 'components' => [ - // 引入RPC组件以及本组件 - 'Rpc' => 'Imi\Rpc', - 'Hprose' => 'Imi\Hprose', - ], -] -``` - -如果你用主服务器: - -```php -[ - // 主服务器配置 - 'mainServer' => [ - 'namespace' => 'XXX\MainServer', // 你的命名空间 - 'type' => 'Hprose', // 必须设为 Hprose - 'port' => 8080, - ], -] -``` - -如果你用子服务器: - -```php -[ - // 子服务器(端口监听)配置 - 'subServers' => [ - // 子服务器名 - 'XXX' => [ - 'namespace' => 'XXX\Hprose', // 你的命名空间 - 'type' => 'Hprose', // 必须设为 Hprose - 'port' => 50001, - ] - ], -] -``` - -### 控制器基类 - -`Imi\Rpc\Controller\RpcController` - -### 控制器注解 - -`\Imi\Rpc\Route\Annotation\RpcController` - -用法: - -`@RpcController` - -别名前缀:`@RpcController('a_b_')` - -### 动作注解 - -`\Imi\Rpc\Route\Annotation\RpcAction` - -无参 - -### 路由注解 - -`\Imi\Hprose\Route\Annotation\HproseRoute` - -参数: - -- `name` 路由名称规则。一般也是方法名,如果设置了别名,则最终为别名+方法名 -- `mode` 该设置表示该服务函数返回的结果类型,具体值请参考 Hprose 文档 -- `simple` 该设置表示本服务函数所返回的结果是否为简单数据。默认值为 false。 -- `oneway` 该设置表示本服务函数是否不需要等待返回值。当该设置为 true 时,调用会异步开始,并且不等待结果,立即返回 null 给客户端。默认值为 false。 -- `async` 该设置表示本服务函数是否为异步函数,异步函数的最后一个参数是一个回调函数,用户需要在异步函数中调用该回调方法来传回返回值 -- `passContext` 该属性为 boolean 类型,默认值为 false。具体请参考 Hprose 文档 - -> Hprose 文档参考: - -## 客户端 - -### 连接池配置 - -```php -[ - 'pools' => [ - '连接池名' => [ - 'sync' => [ - 'pool' => [ - 'class' => \Imi\Rpc\Client\Pool\RpcClientSyncPool::class, - 'config' => [ - // 连接池通用,查阅文档 - ], - ], - 'resource' => [ - 'clientClass' => \Imi\Hprose\Client\HproseSocketClient::class, - 'uris' => 'tcp://127.0.0.1:50001', // 连接地址 - // 其它配置 - ] - ], - 'async' => [ - 'pool' => [ - 'class' => \Imi\Rpc\Client\Pool\RpcClientCoroutinePool::class, - 'config' => [ - // 连接池通用,查阅文档 - ], - ], - 'resource' => [ - 'clientClass' => \Imi\Hprose\Client\HproseSocketClient::class, - 'uris' => 'tcp://127.0.0.1:50001', // 连接地址 - // 其它配置 - ] - ], - ], - ], - 'rpc' => [ - 'defaultPool' => '连接池名', // 默认连接池名 - ], -] -``` - -### 客户端调用 - -代码调用: - -```php -\Imi\Rpc\Client\Pool\RpcClientPool::getService('服务名')->方法名(参数); -``` - -注解调用: - -```php -class Test -{ - /** - * @RpcClient() - * - * @var \Imi\Rpc\Client\IRpcClient - */ - protected $rpcClient; - - /** - * @RpcService(serviceName="服务名") - * - * @var \Imi\Rpc\Client\IService - */ - protected $xxxRpc; - - public function aaa() - { - // 方法一 - $this->rpcClient->getService('服务名')->方法名(参数); - - // 方法二 - $this->xxxRpc->方法名(参数); - } -} -``` - -## 免费技术支持 - -QQ群:17916227 [![点击加群](https://pub.idqqimg.com/wpa/images/group.png "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq),如有问题会有人解答和修复。 - -## 运行环境 - -- [PHP](https://php.net/) >= 8.1 -- [Composer](https://getcomposer.org/) >= 2.0 -- [Swoole](https://www.swoole.com/) >= 4.1.0 - -## 版权信息 - -`imi-hprose` 遵循 MulanPSL-2.0 开源协议发布,并提供免费使用。 - -## 捐赠 - - - -开源不求盈利,多少都是心意,生活不易,随缘随缘…… diff --git a/src/Components/hprose/composer.json b/src/Components/hprose/composer.json deleted file mode 100644 index 6ff6f78702..0000000000 --- a/src/Components/hprose/composer.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "imiphp/imi-hprose", - "type": "library", - "license": "MulanPSL-2.0", - "description": "在 imi 框架中集成 Hprose 服务开发", - "require": { - "hprose/hprose": "^2.0", - "hprose/hprose-swoole": "^2.0.12", - "imiphp/imi-rpc": "~3.0.0", - "imiphp/imi-swoole": "~3.0.0" - }, - "require-dev": {}, - "autoload": { - "psr-4": { - "Imi\\Hprose\\": "src/", - "Imi\\Server\\Hprose\\": "src/Imi-Server-Hprose/" - } - }, - "autoload-dev": { - "psr-4": { - "Imi\\Hprose\\Dev\\": "dev/" - }, - "files": [ - "../../../vendor/autoload.php", - "../../../dev/try-include-swoole.php" - ] - }, - "scripts": { - "pre-install-cmd": "Imi\\Hprose\\Dev\\Dev::preUpdate", - "pre-update-cmd": "Imi\\Hprose\\Dev\\Dev::preUpdate", - "post-install-cmd": "Imi\\Hprose\\Dev\\Dev::postUpdate", - "post-update-cmd": "Imi\\Hprose\\Dev\\Dev::postUpdate" - }, - "minimum-stability": "dev", - "prefer-stable": true -} \ No newline at end of file diff --git a/src/Components/hprose/dev/Dev.php b/src/Components/hprose/dev/Dev.php deleted file mode 100644 index 7d28f46821..0000000000 --- a/src/Components/hprose/dev/Dev.php +++ /dev/null @@ -1,77 +0,0 @@ -getComposer()->getPackage(); - $requires = $package->getRequires(); - foreach ($requires as $name => &$require) - { - if ('imiphp/' !== substr($name, 0, 7) || !is_dir(\dirname($dir) . '/' . substr($name, 11))) - { - continue; - } - // @phpstan-ignore-next-line - $require = new Link($require->getSource(), $require->getTarget(), new MultiConstraint([ - new Constraint('>=', '3.0'), - new Constraint('<', '3.1'), - ]), $require->getDescription()); - } - $package->setRequires($requires); - - $requires = $package->getDevRequires(); - foreach ($requires as $name => &$require) - { - if ('imiphp/' !== substr($name, 0, 7) || !is_dir(\dirname($dir) . '/' . substr($name, 11))) - { - continue; - } - // @phpstan-ignore-next-line - $require = new Link($require->getSource(), $require->getTarget(), new MultiConstraint([ - new Constraint('>=', '3.0'), - new Constraint('<', '3.1'), - ]), $require->getDescription()); - } - $package->setDevRequires($requires); - } - - // @phpstan-ignore-next-line - public static function postUpdate(Event $event): void - { - // @phpstan-ignore-next-line - $componentsName = $event->getComposer()->getPackage()->getName(); - $dir = \dirname(__DIR__); - - foreach (InstalledVersions::getInstalledPackages() as $name) - { - if ($componentsName === $name) - { - continue; - } - $componentDir = \dirname($dir) . '/' . substr($name, 11); - if ('imiphp/' !== substr($name, 0, 7) || !is_dir($componentDir)) - { - continue; - } - - $path = "{$dir}/vendor/{$name}"; - $cmd = "rm -rf {$path} && ln -s -f {$componentDir} {$path}"; - echo '[cmd] ', $cmd, \PHP_EOL; - echo shell_exec($cmd), \PHP_EOL; - } - } -} diff --git a/src/Components/hprose/rector.php b/src/Components/hprose/rector.php deleted file mode 100644 index 5e23e0976d..0000000000 --- a/src/Components/hprose/rector.php +++ /dev/null @@ -1,5 +0,0 @@ -client = $client; - $this->name = $name; - } - - /** - * {@inheritDoc} - */ - public function getName(): ?string - { - return $this->name; - } - - /** - * {@inheritDoc} - */ - public function call(string $method, array $args = []) - { - return $this->client->getInstance()->{$this->name}->{$method}(...$args); - } - - /** - * 魔术方法. - * - * @param string $name 方法名 - * @param array $arguments 参数 - * - * @return mixed - */ - public function __call($name, $arguments) - { - return $this->call($name, $arguments); - } - - /** - * {@inheritDoc} - */ - public function getClient(): IRpcClient - { - return $this->client; - } -} diff --git a/src/Components/hprose/src/Client/HproseSocketClient.php b/src/Components/hprose/src/Client/HproseSocketClient.php deleted file mode 100644 index 0aad2988ef..0000000000 --- a/src/Components/hprose/src/Client/HproseSocketClient.php +++ /dev/null @@ -1,95 +0,0 @@ -options = $options; - } - - /** - * {@inheritDoc} - */ - public function open(): bool - { - $this->client = new \Hprose\Socket\Client($this->options['uris'], false); - Event::trigger('IMI.RPC.HPROSE.CLIENT.OPEN', [ - 'client' => $this->client, - ], $this); - - return true; - } - - /** - * {@inheritDoc} - */ - public function close(): void - { - $this->client = null; - } - - /** - * {@inheritDoc} - */ - public function isConnected(): bool - { - return true; - } - - /** - * 实时检查是否已连接. - */ - public function checkConnected(): bool - { - return true; - } - - /** - * {@inheritDoc} - */ - public function getInstance(): Client - { - return $this->client; - } - - /** - * {@inheritDoc} - */ - public function getService(?string $name = null): IService - { - return new HproseService($this, $name); - } - - /** - * {@inheritDoc} - */ - public function getOptions(): array - { - return $this->options; - } -} diff --git a/src/Components/hprose/src/Imi-Server-Hprose/Server.php b/src/Components/hprose/src/Imi-Server-Hprose/Server.php deleted file mode 100644 index cc61c924ba..0000000000 --- a/src/Components/hprose/src/Imi-Server-Hprose/Server.php +++ /dev/null @@ -1,264 +0,0 @@ -getServerInitConfig(); - $this->swooleServer = new \Swoole\Server($config['host'], (int) $config['port'], (int) $config['mode'], (int) $config['sockType']); - $this->hproseService = new \Hprose\Swoole\Socket\Service(); - $this->parseConfig($config); - } - - /** - * {@inheritDoc} - */ - protected function createSubServer(): void - { - $config = $this->getServerInitConfig(); - // @phpstan-ignore-next-line - $this->swooleServer = ServerManager::getServer('main')->getSwooleServer(); - $this->swoolePort = $this->swooleServer->addListener((int) $config['host'], (int) $config['port'], (int) $config['sockType']); - $this->swoolePort->set([]); - $this->hproseService = new \Hprose\Swoole\Socket\Service(); - $this->parseConfig($config); - $this->hproseService->onBeforeInvoke = function ($name, &$args, $byref, \stdClass $context) { - $requestContext = RequestContext::create(); - $requestContext['server'] = $this; - $this->trigger('BeforeInvoke', [ - 'name' => $name, - 'args' => &$args, - 'byref' => $byref, - 'context' => $context, - ], $this); - }; - $this->hproseService->onAfterInvoke = function ($name, $args, $byref, &$result, \stdClass $context) { - $this->trigger('AfterInvoke', [ - 'name' => $name, - 'args' => $args, - 'byref' => $byref, - 'context' => $context, - 'result' => &$result, - ], $this); - if ($result instanceof \Imi\Model\BaseModel) - { - $result = $result->toArray(); - } - PoolManager::destroyCurrentContext(); - RequestContext::destroy(); - }; - $this->hproseService->onSendError = static function (\Throwable $error, \stdClass $context) { - Log::error($error->getMessage(), [ - 'trace' => $error->getTrace(), - 'errorFile' => $error->getFile(), - 'errorLine' => $error->getLine(), - ]); - PoolManager::destroyCurrentContext(); - RequestContext::destroy(); - }; - } - - /** - * {@inheritDoc} - */ - protected function getServerInitConfig(): array - { - $host = $this->config['host'] ?? '0.0.0.0'; - $sockType = \Imi\Swoole\Util\Swoole::getTcpSockTypeByHost($host); - - return [ - 'host' => $host, - 'port' => (int) ($this->config['port'] ?? 8080), - 'sockType' => isset($this->config['sockType']) ? ($sockType | $this->config['sockType']) : $sockType, - 'mode' => (int) ($this->config['mode'] ?? \SWOOLE_BASE), - ]; - } - - /** - * 处理服务器配置. - */ - private function parseConfig(array $config): void - { - if (\SWOOLE_UNIX_STREAM !== $config['sockType']) - { - $this->config['configs']['open_tcp_nodelay'] = true; - } - $this->config['configs']['open_eof_check'] = false; - $this->config['configs']['open_length_check'] = false; - $this->config['configs']['open_eof_split'] = false; - } - - /** - * {@inheritDoc} - */ - public function on($name, $callback, int $priority = 0): void - { - if ($this->isHookHproseOn) - { - parent::on($name, function (EventParam $e) use ($callback) { - $data = $e->getData(); - $data['server'] = $this->swooleServer; - $callback(...array_values($data)); - }, $priority); - } - else - { - parent::on($name, $callback, $priority); - } - } - - /** - * {@inheritDoc} - */ - protected function __bindEvents(): void - { - $server = $this->swoolePort; - - $this->isHookHproseOn = true; - $this->hproseService->socketHandle($this); - $this->isHookHproseOn = false; - - $server->on('connect', function (\Swoole\Server $server, $fd, $reactorId) { - try - { - $this->trigger('connect', [ - 'server' => $this, - 'clientId' => $fd, - 'reactorId' => $reactorId, - ], $this, ConnectEventParam::class); - } - catch (\Throwable $th) - { - Log::error($th); - } - }); - - $server->on('receive', function (\Swoole\Server $server, $fd, $reactorId, $data) { - try - { - $this->trigger('receive', [ - 'server' => $this, - 'clientId' => $fd, - 'reactorId' => $reactorId, - 'data' => $data, - ], $this, ReceiveEventParam::class); - } - catch (\Throwable $th) - { - Log::error($th); - } - }); - - $server->on('close', function (\Swoole\Server $server, $fd, $reactorId) { - try - { - $this->trigger('close', [ - 'server' => $this, - 'clientId' => $fd, - 'reactorId' => $reactorId, - ], $this, CloseEventParam::class); - } - catch (\Throwable $th) - { - Log::error($th); - } - }); - } - - /** - * Get hprose Service. - */ - public function getHproseService(): \Hprose\Swoole\Socket\Service - { - return $this->hproseService; - } - - /** - * {@inheritDoc} - */ - public function getRpcType(): string - { - return 'Hprose'; - } - - /** - * {@inheritDoc} - */ - public function getControllerAnnotation(): string - { - return \Imi\Rpc\Route\Annotation\RpcController::class; - } - - /** - * {@inheritDoc} - */ - public function getActionAnnotation(): string - { - return \Imi\Rpc\Route\Annotation\RpcAction::class; - } - - /** - * {@inheritDoc} - */ - public function getRouteAnnotation(): string - { - return \Imi\Hprose\Route\Annotation\HproseRoute::class; - } - - /** - * {@inheritDoc} - */ - public function getRouteClass(): string - { - return 'HproseRoute'; - } - - /** - * {@inheritDoc} - */ - public function isLongConnection(): bool - { - return true; - } - - /** - * {@inheritDoc} - */ - public function isSSL(): bool - { - return false; - } - - /** - * {@inheritDoc} - */ - public function getProtocol(): string - { - return Protocol::TCP; - } -} diff --git a/src/Components/hprose/src/Listener/AddRouteRule.php b/src/Components/hprose/src/Listener/AddRouteRule.php deleted file mode 100644 index ee90db07a1..0000000000 --- a/src/Components/hprose/src/Listener/AddRouteRule.php +++ /dev/null @@ -1,62 +0,0 @@ -getData(); - $this->addRuleAnnotation($data['annotation'], $data['callable'], $data['options']); - } - - /** - * 增加路由规则,直接使用注解方式. - * - * @param mixed $callable - */ - private function addRuleAnnotation(HproseRouteAnnotation $annotation, $callable, array $options = []): void - { - $serverName = $options['serverName']; - $controllerAnnotation = $options['controller']; - /** @var \Hprose\Swoole\Socket\Service $hproseServer */ - // @phpstan-ignore-next-line - $hproseServer = ServerManager::getServer($serverName)->getHproseService(); - - // alias - if (Text::isEmpty($controllerAnnotation->prefix)) - { - $alias = $annotation->name; - } - else - { - $alias = $controllerAnnotation->prefix . $annotation->name; - } - - // funcOptions - $funcOptions = [ - 'mode' => $annotation->mode, - 'simple' => $annotation->simple, - 'oneway' => $annotation->oneway, - 'async' => $annotation->async, - 'passContext' => $annotation->passContext, - ]; - - $hproseServer->addFunction($callable, $alias, $funcOptions); - } -} diff --git a/src/Components/hprose/src/Listener/InitDefaultRoute.php b/src/Components/hprose/src/Listener/InitDefaultRoute.php deleted file mode 100644 index c65eb8ab9d..0000000000 --- a/src/Components/hprose/src/Listener/InitDefaultRoute.php +++ /dev/null @@ -1,37 +0,0 @@ -getData(); - $this->init($data['className'], $data['classAnnotation'], $data['methodName'], $data['result']); - } - - /** - * 初始化. - */ - private function init(string $className, RpcController $classAnnotation, string $methodName, ?RpcRoute &$result): void - { - $result = new HproseRoute([ - 'name' => $methodName, - ]); - } -} diff --git a/src/Components/hprose/src/Main.php b/src/Components/hprose/src/Main.php deleted file mode 100644 index a9e7fdd335..0000000000 --- a/src/Components/hprose/src/Main.php +++ /dev/null @@ -1,14 +0,0 @@ -getHproseService(); - - // alias - if (Text::isEmpty($controllerAnnotation->prefix)) - { - $alias = $routeAnnotation->name; - } - // @phpstan-ignore-next-line - elseif (\is_string($routeAnnotation->name)) - { - $alias = $controllerAnnotation->prefix . $routeAnnotation->name; - } - else - { - throw new \RuntimeException('Invalid route'); - } - - // funcOptions - $funcOptions = [ - 'mode' => $routeAnnotation->mode, - 'simple' => $routeAnnotation->simple, - 'oneway' => $routeAnnotation->oneway, - 'async' => $routeAnnotation->async, - 'passContext' => $routeAnnotation->passContext, - ]; - - $hproseServer->addFunction($callable, $alias, $funcOptions); - } - - /** - * {@inheritDoc} - */ - public function getDefaultRouteAnnotation(string $className, string $methodName, IRpcController $controllerAnnotation, array $options = []): HproseRoute - { - return new HproseRoute([ - 'name' => $methodName, - ]); - } -} diff --git a/src/Components/hprose/src/config/config.php b/src/Components/hprose/src/config/config.php deleted file mode 100644 index 3a2ee8e088..0000000000 --- a/src/Components/hprose/src/config/config.php +++ /dev/null @@ -1,11 +0,0 @@ - [ - 'Imi\Hprose\Listener', - 'Imi\Hprose\Route', - 'Imi\Server\Hprose', - ], -]; diff --git a/src/Components/rpc/README.md b/src/Components/rpc/README.md index 9cad168c7b..7d5cf58c36 100644 --- a/src/Components/rpc/README.md +++ b/src/Components/rpc/README.md @@ -9,8 +9,6 @@ 在 imi 框架中开发 RPC 服务的基础组件。本组件不提供实际的 RPC 实现,仅提供开发 RPC 服务的一些插槽。 -`imi-hprose` 基于 `imi-rpc` 实现: - > 本仓库仅用于浏览,不接受 issue 和 Pull Requests,请前往: ## Composer diff --git a/website/src/page/index.html b/website/src/page/index.html index 0292fd96a3..144edf178e 100644 --- a/website/src/page/index.html +++ b/website/src/page/index.html @@ -237,7 +237,6 @@

target="_blank">负载均衡
  • 限流
  • gRPC
  • -
  • Hprose