2017 © Pedro PelĂĄez
 

project psr15-router

Component to route PSR-7 requests through PSR-15 middlewares

image

ajgarlag/psr15-router

Component to route PSR-7 requests through PSR-15 middlewares

  • Monday, September 25, 2017
  • by ajgarlag
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,534 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 12 % Grown

The README.md

Psr15 Router

The Psr15 Router component allows you to route PSR-7 requests through PSR-15 middlewares., (*1)

Build Status Latest Stable Version Latest Unstable Version Total Downloads Montly Downloads Daily Downloads License, (*2)

Installation

To install the latest stable version of this component, open a console and execute the following command:, (*3)

$ composer require ajgarlag/psr15-router

Usage

You can choose if you want to route your request through a MiddlewareInterface or a RequestHandlerInterface, (*4)

Middleware routing

With this option, you has to build a Router to discriminate which middleware will process the request. Then build RouterMiddleware to process the request:, (*5)

use Ajgarlag\Psr15\Router\Matcher\UriRegexRequestMatcher;
use Ajgarlag\Psr15\Router\Middleware\Route;
use Ajgarlag\Psr15\Router\Middleware\ArrayRouter;
use Ajgarlag\Psr15\Router\Middleware\RouterMiddleware;

$userMiddleware; //Some middleware to process user requests
$userRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/user/'),
    $userMiddleware
);
$adminMiddleware; //Some middleware to process admin requests
$adminRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/admin/'),
    $adminMiddleware
);

$router = new ArrayRouter();
$router->addRoute($userRoute);
$router->addRoute($adminRoute);

$routerMiddleware = new RouterMiddleware($router);

$response = $routerMiddleware->process($request, $requestHandler);

If the router does not return any middleware to process the request, it is processed directly through the request handler., (*6)

Request handler routing

With this option, you has to build a Router to discriminate which request handler will process the request. Then build RouterRequestHandler to process the request. A failover request handler is required to process the request if the router cannot route the request. Usually this failover request handler should return a 404 response., (*7)

use Ajgarlag\Psr15\Router\Matcher\UriRegexRequestMatcher;
use Ajgarlag\Psr15\Router\RequestHandler\Route;
use Ajgarlag\Psr15\Router\RequestHandler\ArrayRouter;
use Ajgarlag\Psr15\Router\RequestHandler\RouterRequestHandler;

$userRequestHandler; //Some request handler to process user requests
$userRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/user/'),
    $userRequestHandler
);
$adminRequestHandler; //Some request handler to process admin requests
$adminRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/admin/'),
    $adminRequestHandler
);

$router = new ArrayRouter();
$router->addRoute($userRoute);
$router->addRoute($adminRoute);

$failoverRequestHandler; // Request handler that returns 404 unconditionally
$routerRequestHandler = new RouterRequestHandler($router, $failoverRequestHandler);

$response = $routerRequestHandler->handle($request);

License

This component is under the MIT license. See the complete license in the LICENSE file., (*8)

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker., (*9)

Author Information

Developed with ♄ by Antonio J. GarcĂ­a Lagar., (*10)

If you find this component useful, please add a ★ in the GitHub repository page and/or the Packagist package page., (*11)

The Versions

25/09 2017

dev-master

9999999-dev

Component to route PSR-7 requests through PSR-15 middlewares

  Sources   Download

MIT

The Requires

 

The Development Requires

25/09 2017
20/09 2017

0.2.0

0.2.0.0

Component to route PSR-7 requests through PSR-15 middlewares

  Sources   Download

MIT

The Requires

 

The Development Requires

20/09 2017

dev-request-handler

dev-request-handler

Component to route PSR-7 requests through PSR-15 middlewares

  Sources   Download

MIT

The Requires

 

The Development Requires

17/07 2017

0.1.1

0.1.1.0

Component to route PSR-7 requests through PSR-15 middlewares

  Sources   Download

MIT

The Requires

 

The Development Requires

14/07 2017

0.1.0

0.1.0.0

Component to route PSR-7 requests through PSR-15 middlewares

  Sources   Download

MIT

The Requires

 

The Development Requires