chubbyphp / chubbyphp-framework-router-symfony
symfony router implementation for chubbyphp-framework.
2.1.0
2023-12-02 20:13 UTC
Requires
- php: ^8.1
- chubbyphp/chubbyphp-framework: ^5.1
- chubbyphp/chubbyphp-http-exception: ^1.1
- psr/http-message: ^1.1|^2.0
- symfony/expression-language: ^5.4.31|^6.3.8|^7.0
- symfony/routing: ^5.4.31|^6.3.8|^7.0
Requires (Dev)
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-mock: ^1.7
- guzzlehttp/psr7: ^2.6.1
- http-interop/http-factory-guzzle: ^1.2
- infection/infection: ^0.27.8
- laminas/laminas-diactoros: ^3.3
- nyholm/psr7: ^1.8.1
- php-coveralls/php-coveralls: ^2.7.0
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan: ^1.10.45
- phpunit/phpunit: ^10.4.2
- slim/psr7: ^1.6.1
- sunrise/http-message: ^3.0
README
Description
Symfony Router implementation for chubbyphp-framework.
Requirements
- php: ^8.1
- chubbyphp/chubbyphp-framework: ^5.1
- chubbyphp/chubbyphp-http-exception: ^1.1
- psr/http-message: ^1.1|^2.0
- symfony/expression-language: ^5.4.31|^6.3.8|^7.0
- symfony/routing: ^5.4.31|^6.3.8|^7.0
Installation
Through Composer as chubbyphp/chubbyphp-framework-router-symfony.
composer require chubbyphp/chubbyphp-framework-router-symfony "^2.1"
Usage
<?php declare(strict_types=1); namespace App; use Chubbyphp\Framework\Application; use Chubbyphp\Framework\Middleware\ExceptionMiddleware; use Chubbyphp\Framework\Middleware\RouterMiddleware; use Chubbyphp\Framework\RequestHandler\CallbackRequestHandler; use Chubbyphp\Framework\Router\Symfony\Router; use Chubbyphp\Framework\Router\Route; use Psr\Http\Message\ServerRequestInterface; use Slim\Psr7\Factory\ResponseFactory; use Slim\Psr7\Factory\ServerRequestFactory; $loader = require __DIR__.'/vendor/autoload.php'; $responseFactory = new ResponseFactory(); $app = new Application([ new ExceptionMiddleware($responseFactory, true), new RouterMiddleware(new SymfonyRouter([ Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); return $response; } ), [], [SymfonyRouter::PATH_REQUIREMENTS => ['name' => '[a-z]+']]) ])), ]); $app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));
Copyright
2024 Dominik Zogg