2017 © Pedro Peláez
 

library http-router

Thruster HttpRouter Component (PSR-7 and FastRoute based router)

image

thruster/http-router

Thruster HttpRouter Component (PSR-7 and FastRoute based router)

  • Tuesday, May 31, 2016
  • by gcds
  • Repository
  • 3 Watchers
  • 7 Stars
  • 430 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 21 % Grown

The README.md

HttpRouter Component

[Latest Version] (https://github.com/ThrusterIO/http-router/releases) [Software License] (LICENSE) [Build Status] (https://travis-ci.org/ThrusterIO/http-router) [Code Coverage] (https://scrutinizer-ci.com/g/ThrusterIO/http-router) [Quality Score] (https://scrutinizer-ci.com/g/ThrusterIO/http-router) [Total Downloads] (https://packagist.org/packages/thruster/http-router), (*1)

[Email] (mailto:team@thruster.io), (*2)

The Thruster HttpRoute Component. PSR-7 and FastRoute based simple router., (*3)

Install

Via Composer, (*4)

$ composer require thruster/http-router

Usage

Standalone usage

<?php

use Psr\Http\Message\RequestInterface;
use Thruster\Component\HttpRouter\Router;
use Thruster\Component\HttpRouter\RouteProvider;

$application = new class implements RouteProvider {
    public function getRoutes() : array
    {
        return [
            'hello_world' => ['GET', '/', 'hello'],
            ['POST', '/', [$this, 'foo']]
        ];
    }

    public function hello(ServerRequestInterface $request)
    {
        // return new Response(200, [], 'Hello world');
    }

    public function foo(ServerRequestInterface $request)
    {
        // return new Response(404, [], 'Foo Bar');
    }
};


$router = new Router($application);
$response = $router->handleRequest(ServerRequest::fromGlobals()); // PSR-7 Response

PSR-7 style middleware

<?php

use Psr\Http\Message\RequestInterface;
use Thruster\Component\HttpRouter\Router;
use Thruster\Component\HttpRouter\RouteProvider;
use Thruster\Component\HttpRouter\RouteHandler;

$application = new class implements RouteProvider, RouteHandler {
    public function getRoutes() : array
    {
        return [
            'hello_world' => ['GET', '/', 'hello'],
            ['POST', '/', [$this, 'foo']]
        ];
    }

    public function handleRoute(
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $actionHandler
    ) : ResponseInterface {
        // ... call actionHandler and return ResponseInterface
    }

    public function handleRouteMethodNotAllowed(
        ServerRequestInterface $request,
        ResponseInterface $response,
        array $allowedMethods
    ) : ResponseInterface {
        // ... handle method not allowed error
    }

    public function handleRouteNotFound(
        ServerRequestInterface $request,
        ResponseInterface $response
    ) : ResponseInterface {
        // ... handle route not found (404)
    }
};


$router = new Router($application, $application);
$response = $router(ServerRequest::fromGlobals(), new Response()); // PSR-7 Response

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*5)

License

Please see License File for more information., (*6)

The Versions

31/05 2016

dev-master

9999999-dev https://thruster.io

Thruster HttpRouter Component (PSR-7 and FastRoute based router)

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http router fastroute fast-route thruster http-router httprouter

31/05 2016

1.1.0

1.1.0.0 https://thruster.io

Thruster HttpRouter Component (PSR-7 and FastRoute based router)

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http router fastroute fast-route thruster http-router httprouter

09/01 2016

1.0.0

1.0.0.0 https://thruster.io

Thruster HttpRouter Component (PSR-7 and FastRoute based router)

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http router fastroute fast-route thruster http-router httprouter