99designs / twirfony
v2.0.0
2023-08-27 22:32 UTC
Requires
- php: >=7
- ext-json: *
- google/protobuf: ^3
- guzzlehttp/guzzle: ^6
- psr/http-message: ^1
- symfony/symfony: ~4|~5
Requires (Dev)
- phpunit/phpunit: ^9.6
- symfony/phpunit-bridge: ^6.1
- dev-master
- v2.0.0
- 1.0.1
- 1.0.0
- 0.1.4
- 0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-dependabot/composer/protoc-gen-twirp_php/examples/clientcompat/guzzlehttp/psr7-1.9.1
- dev-dependabot/composer/protoc-gen-twirp_php/examples/clientcompat/guzzlehttp/guzzle-6.5.8
- dev-dependabot/composer/protoc-gen-twirp_php/examples/clientcompat/google/protobuf-3.15.0
- dev-composer-changes
- dev-upgrade-protobuf-version
This package is auto-updated.
Last update: 2024-08-28 00:37:42 UTC
README
Twirfony 由两部分组成,代码生成和运行时 Symfony 扩展。
代码生成
代码生成是用 Golang 编写的 protoc 插件,因为 Go 的 proto 工具非常出色。
生成 twirp 接口
go install ./protoc-gen-twirp_php protoc --twirp_php_out src --php_out src haberdasher.proto
‼️ 在 99designs 中,您应该使用 99dev twirp generate {app}
,并阅读https://github.com/99designs/twirpgen 上的文档
运行时
运行时组件是一个允许您将实现生成的 twirp 服务接口的类直接挂载到路由器中的 Symfony 扩展。
- 添加 twirfony 依赖
composer require 99designs/twirfony
- 注册扩展
class AppKernel extends Kernel { public function registerBundles() { return [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new AppBundle\AppBundle(), new Twirfony\TwirfonyBundle\TwirfonyBundle(), // add this line ]; }
- 在 routing.yml 中注册路由器
twirp_api: resource: 'twirp.service_registry::loadRoutes' type: service prefix: /twirp
- 创建并实现您的 twirp 服务
namespace AppBundle\Service; use AppBundle\Twirp\HaberdasherInterface; use AppBundle\Twirp\Hat; use AppBundle\Twirp\Size; use Twirfony\TwirpService; class HaberdasherService implements TwirpService, HaberdasherInterface { public function makeHat(Size $size): Hat { return (new Hat) ->setInches($size->getInches()) ->setColor("blue") ->setName("Fedora"); } }
- 注册并标记您的服务
haberdasher_service: class: AppBundle\Service\HaberdasherService tags: ['twirp.service']