99designs / twirfony
Installs: 5 283
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 39
Forks: 3
Open Issues: 3
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-11-28 01:17:31 UTC
README
Twirfony is made up of two parts, codegen and a runtime Symfony bundle.
Code generation
Code generation is written as a protoc plugin in golang, because the go tooling for proto is fantastic.
To generate the twirp interfaces
go install ./protoc-gen-twirp_php protoc --twirp_php_out src --php_out src haberdasher.proto
‼️ At 99designs you should use 99dev twirp generate {app}
instead, and read the docs over at https://github.com/99designs/twirpgen
Runtime
The runtime component is a Symfony bundle that allows you to mount classes implementing the generated twirp service interfaces directly into your router.
- Add a twirfony dependency
composer require 99designs/twirfony
- Register the bundle
class AppKernel extends Kernel { public function registerBundles() { return [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new AppBundle\AppBundle(), new Twirfony\TwirfonyBundle\TwirfonyBundle(), // add this line ]; }
- Register the router in routing.yml
twirp_api: resource: 'twirp.service_registry::loadRoutes' type: service prefix: /twirp
- Create implement your twirp service
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"); } }
- Register and tag your service
haberdasher_service: class: AppBundle\Service\HaberdasherService tags: ['twirp.service']