Pollen Solutions - Routing Component - HTTP request mapping and HTTP response resolution.

v1.0.10 2023-01-04 00:00 UTC

This package is auto-updated.

Last update: 2024-04-13 12:22:28 UTC


Latest Stable Version MIT Licensed PHP Supported Versions

Pollen Solutions Routing Component provide a layer of HTTP request mapping and HTTP response resolution.


composer require pollen-solutions/routing

Basic Usage

<?php declare(strict_types=1);

use Pollen\Http\Request;
use Pollen\Http\Response;
use Pollen\Http\ResponseInterface;
use Pollen\Routing\Router;

// Router instantiation
$router = new Router();

// Map a route
$router->map('GET', '/', static function (): ResponseInterface {
    return new Response('<h1>Hello, World!</h1>');

$router->map('GET', '/phpinfo', static function () {
    return new Response(ob_get_clean());

// Setting Handle Request (optional)
$psrRequest = Request::createFromGlobals()->psr();

// Map a Fallback Route (optional)
$router->setFallback(function () {
    return new Response('<h1>404 - Page not found !</h1>', 404);

// Catch HTTP Response
$response = $router->handle($psrRequest);

// Send the response to the browser

// Trigger the terminate event
$router->terminate($psrRequest, $response);