palabs / endpoint-bundle
Symfony Endpoint bundle
Installs: 3 034
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^8.0
- symfony/config: ^5.0 || ^6.0
- symfony/dependency-injection: ^5.0 || ^6.0
- symfony/filesystem: ^5.0 || ^6.0
- symfony/http-foundation: ^5.0 || ^6.0
- symfony/http-kernel: ^5.0 || ^6.0
- symfony/routing: ^5.0 || ^6.0
README
PaEndpointBundle add alternative to symfony controllers. Endpoint is a controller with only one method - execute(Request): Response
Features include:
- 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:
composer require palabs/endpoint-bundle
Register bundle in Kernel:
// app/AppKernel.php public function registerBundles() { return [ // ... new PaLabs\EndpointBundle\PaEndpointBundle(), // ... ]; }
Add route loading in app/config/routing.yml:
endpoints: resource: . type: endpoints
Usage
A simple endpoint look like
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'); } }