2017 © Pedro Peláez
 

symfony-bundle endpoint-bundle

Symfony Endpoint bundle

image

palabs/endpoint-bundle

Symfony Endpoint bundle

  • Tuesday, July 31, 2018
  • by lewbor
  • Repository
  • 1 Watchers
  • 3 Stars
  • 727 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 11 % Grown

The README.md

PaEndpointBundle

PaEndpointBundle add alternative to symfony controllers. Endpoint is a controller with only one method - execute(Request): Response, (*1)

Features include:, (*2)

  • Simple and clean endpoint interface - only one request handler in one class
  • Easy way to generate routes, e.g. $router->url(SomeEndpoint::class)
  • Refactorable - no additional changes need if you move or rename endpoint
  • No route names need (but if you want you can specify it in route definition)
  • Supports for extending endpoints - you can define base endpoints and many childs with shared routes configuration. It's is very common task in crud controllers.

Installation

Add bundle to you composer.json:, (*3)

composer require palabs/endpoint-bundle

Register bundle in Kernel:, (*4)

// app/AppKernel.php

public function registerBundles()
{
    return [
        // ...
        new PaLabs\EndpointBundle\PaEndpointBundle(),
        // ...
    ];
}

Add route loading in app/config/routing.yml:, (*5)

endpoints:
  resource: .
  type: endpoints

Usage

A simple endpoint look like, (*6)

use PaLabs\EndpointBundle\EndpointInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TextEndpoint implements EndpointInterface {

    public function routes()
    {
       return new Route('/cool_message');
    }


    public function execute(Request $request): Response
    {
       return new Response('Hello, world');
    }
}

The Versions