https://github.com/99designs/twirfony
Symfony support for Twirp
https://github.com/99designs/twirfony
php symfony twirp
Last synced: 3 months ago
JSON representation
Symfony support for Twirp
- Host: GitHub
- URL: https://github.com/99designs/twirfony
- Owner: 99designs
- License: mit
- Created: 2018-02-21T11:14:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-27T22:37:59.000Z (about 2 years ago)
- Last Synced: 2025-06-04T12:25:50.309Z (4 months ago)
- Topics: php, symfony, twirp
- Language: PHP
- Homepage:
- Size: 122 KB
- Stars: 3
- Watchers: 39
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# twirfony: twirp for Symfony
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
```bash
go install ./protoc-gen-twirp_php
protoc --twirp_php_out src --php_out src haberdasher.proto
```:bangbang: 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.
1. Add a twirfony dependency
```bash
composer require 99designs/twirfony
```
2. Register the bundle
```php
class AppKernel extends Kernel
{
public function registerBundles()
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new AppBundle\AppBundle(),
new Twirfony\TwirfonyBundle\TwirfonyBundle(), // add this line
];
}
```3. Register the router in routing.yml
```yaml
twirp_api:
resource: 'twirp.service_registry::loadRoutes'
type: service
prefix: /twirp
```4. Create implement your twirp service
```php
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");
}
}
```5. Register and tag your service
```yaml
haberdasher_service:
class: AppBundle\Service\HaberdasherService
tags: ['twirp.service']
```