Code generation
To start building a Twirp service and generate the necessary code for it, you are going to need three things:
- the
protoc
tool - the TwirPHP
protoc
plugin (protoc-gen-twirp_php
) - some proto file that contains service definitions (see the Quickstart guide for an example)
Check out the Installation guide for details about installing protoc
and protoc-gen-twirp_php
.
Based on where you installed protoc-gen-twirp_php
, you might have to invoke the protoc
tool differently:
- Plugin installed in PATH
- Plugin installed in custom path
protoc --twirp_php_out=generated/ --php_out=generated/ service.proto
protoc \
--plugin=protoc-gen-twirp_php=path/to/protoc-gen-twirp_php \
--twirp_php_out=generated/ \
--php_out=generated/ \
service.proto
The resulting directory structure should look something like this:
.
├── GPBMetadata // Some protobuf specific files
│ └── Service.php
└── Twitch
└── Twirp
└── Example
├── Haberdasher.php // Service interface
├── HaberdasherAbstractClient.php // Most of the generated client code
├── HaberdasherClient.php // Protobuf client
├── HaberdasherJsonClient.php // JSON client
├── HaberdasherServer.php // Server implementation
├── Hat.php // Message
├── Size.php // Message
└── TwirpError.php // Exception thrown for most Twirp errors