amrelnaggar/thrift

Apache Thrift 包用于 Laravel 5

此包的规范仓库似乎已消失,因此已冻结该包。

v0.11.0 2018-07-08 04:47 UTC

This package is not auto-updated.

Last update: 2019-12-08 08:13:48 UTC


README

需求

此包已与以下版本测试过,但可能也适用于其他版本

  • PHP 7.1
  • Apache Thrift 0.11.0
  • Laravel 5.6

安装

Laravel Thrift 需要 PHP 7.1 或 7.2。此版本仅支持 Laravel 5.5 或 5.6。

要获取最新版本,只需使用 Composer 引入项目。

$ composer require amrelnaggar/thrift

安装后,如果您未使用自动包发现,则需要将 AmrElNaggar\Thrift\ThriftServiceProvider 服务提供者在您的 config/app.php 中注册。

您还可以选择性地为我们的外观创建别名

        'Thrift' => AmrElNaggar\Thrift\ThriftFacade::class,

配置

发布配置文件

php artisan vendor:publish --provider="AmrElNaggar\Thrift\ThriftServiceProvider"

然后更新 config/thrift.php 以满足您的需求。

    'services' => [
        /**
         * The service name
         *
         * `php artisan thrift:server name`
         */
        'example' => [
            /**
             * Default host name
             */
            'host' => 'localhost',

            /**
             * Default port number
             */
            'port' => 8080,

            /**
             * The class that implements the interface defined in the thrift file.
             *
             * Required
             */
            'service' => '',

            /**
             * The generated class after calling `php artisan thrift:compile example.thrift --namespace=App\Example`
             * e.g. (App\Example\ExampleProcessor)
             *
             * Required in server mode
             */
            'processor' => '',

            /**
             * The generated class after calling `php artisan thrift:compile example.thrift --namespace=App\Example`
             * e.g. (App\Example\ExampleClient)
             *
             * Required in client mode
             */
            'client' => '',
        ],
    ],

用法

1- 编译 .thrift 文件

php artisan thrift:compile {filename} {namespace}
php artisan thrift:compile example.thrift "App\\\Thrift\\\Example"

注意:Thrift 生成的文件不应提交到版本控制系统,请务必将 app/Thrift/Example 或生成的文件所在的目录添加到您的 .gitignore 文件中。

2- 启动 Thrift 服务器

php artisan thrift:server {service} {--host=} {--port}

php artisan thrift:server example --host=localhost --port=8080

3- 测试运行的 Thrift 服务器

php artisan thrift:client {service} {method} {--arg=*} {--host=} {--port}

php artisan thrift:client calculator add --arg=5 --arg=3

4- 使用 Thrift 外观

$service = Thrift::service('calculator');
$result = $service->add(5, 3);
Thrift::shutdown();

更多信息

此包中还有其他一些未在此处记录的类。这是因为它们不是用于公共用途的,而是由本包内部使用的。

安全

如果您在此包中发现安全漏洞,请将电子邮件发送至 Amr El-Naggar 的 amrlnaggar@gmail.com。所有安全漏洞都将得到及时处理。

许可

Laravel Thrift 使用 MIT 许可证 (MIT) 许可。