Giter Club home page Giter Club logo

twirfony's Introduction

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

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.

  1. Add a twirfony dependency
composer require 99designs/twirfony
  1. 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
        ];
    }
  1. Register the router in routing.yml
twirp_api:
    resource: 'twirp.service_registry::loadRoutes'
    type: service
    prefix: /twirp
  1. 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");
    }
}
  1. Register and tag your service
    haberdasher_service:
        class: AppBundle\Service\HaberdasherService
        tags: ['twirp.service']

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.