Download the PHP package timostamm/symfony-twirp-handler without Composer
On this page you can find all versions of the php package timostamm/symfony-twirp-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download timostamm/symfony-twirp-handler
More information about timostamm/symfony-twirp-handler
Files in timostamm/symfony-twirp-handler
Package symfony-twirp-handler
Short Description Helps implementing Twirp in a Symfony application
License MIT
Informations about the package symfony-twirp-handler
Symfony Twirp Handler
Helps implementing Twirp in a Symfony application.
Most simple way
Lets say you have this service defined in a proto file:
First you generate PHP code with protoc, for example:
Then you create a controller for the corresponding Twirp routes:
Twirp route URLs are constructed like this: twirp/{proto package name}.{proto service name}/{proto method name}
.
readTwirp()
and writeTwirp()
will do content negotiation for you.
Supporting errors properly
Twirp has its own error format. To convert exceptions automatically, you can use
the TwirpErrorSubscriber
:
If you have this subscriber set up, you can also throw your own TwirpError
(with
full control over twirp error code and meta data). For documentation about the
arguments of TwirpErrorSubscriber
, check the PHPdoc.
Advanced use
Writing symfony routes for every RPC is tedious and error-prone.
Enable php_generic_services
to generate a PHP interface for each service:
From this file, protoc generates a generic service interface
SearchServiceInterface.php
. Create a new class SearchService
and implement
the interface:
To serve this service via Twirp, you can use the TwirpHandler
. You only need a single
route for one or more services. The handler takes care of the routing, content negotiation,
parsing and serializing and automatically invokes the correct method on your service.
Create a route that matches all twirp/ requests and use the TwirpHandler as follows:
All versions of symfony-twirp-handler with dependencies
google/protobuf Version ^3.10
symfony/property-info Version >=4
symfony/event-dispatcher Version >=4
symfony/http-kernel Version >=4
symfony/http-foundation Version >=4.3
psr/container Version ^1.0