2017 © Pedro Peláez
 

library php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

image

alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  • Monday, July 2, 2018
  • by alexpts
  • Repository
  • 1 Watchers
  • 1 Stars
  • 41 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 64 % Grown

The README.md

psr-15 routing

Build Status Code Coverage Code Climate Scrutinizer Code Quality, (*1)

Install

composer require alexpts/php-psr15-routing, (*2)

Простой роутер с поддержкой PSR-7, PSR-15, (*3)

Возможности

  • Простой захват параметров из url
  • Использование RegExp для описания роута
  • Гибкие группировки для захвата параметров
  • Приоритеты роутов
  • Высокая скорость работы

Example

use PTS\PSR15Routing\CallableAdapter;
use PTS\PSR15Routing\Router;
use PTS\PSR15Routing\Route;
use PTS\PSR15Routing\RouterMiddleware;

$router = new Router;

$router->add('/', new Route('/', new CallableAdapter(function($request) {
    return $response; // $response must be ResponseInterface
})));

$handler = ...; // $handler bust be RequestHandlerInterface
$router->add('/admin', new Route('/', $handler));


// with priority
$router->add('/admin/1', new Route('/', $handler), 100);

// some middleware manager/runner
$app = (new MiddlewareManager)
    ->push(new RouterMiddleware($router);

$response = $app->handler($request);

EndPoint (bonus)

EndPoint is wrapper for real handler route. It need for flex config real handler and get real handler from runtime., (*4)

use PTS\PSR15Routing\CallableAdapter;
use PTS\PSR15Routing\Router;
use PTS\PSR15Routing\Route;
use PTS\PSR15Routing\RouterMiddleware;
use PTS\EndPoint\DynamicPoint;
use PTS\EndPoint\EndPoint;

$router = new Router;

$flexHandler = new DynamicPoint([
    'prefix' => '\\Namespace\\ForDynamicController\\'
]);
$router->add('flex', new Route('/{_controller}/{_action}/', $flexHandler));
// /blog/get/ => \\Namespace\\ForDynamicController\\Blog::get()

$mainPageHandler = new EndPoint(['controller' => SomeController::class]);
$router->add('mainPage', new Route('/', $mainPageHandler)); // SomeController::index()

// with params from url
$postHandler = new DynamicPoint([
    'controller' => '\\Project\\PostController',
]);
$router->add('posts', new Route('/posts/{_action}/{id}/', $postHandler));
// /posts/get/4/ => PostController::get($id = 4)

The Versions

02/07 2018

dev-master

9999999-dev https://github.com/alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

middleware psr-7 routing router psr-15

06/05 2018

2.1.0

2.1.0.0 https://github.com/alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

middleware psr-7 routing router psr-15

02/05 2018

2.0.0

2.0.0.0 https://github.com/alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

middleware psr-7 routing router psr-15

01/05 2018

1.1.0

1.1.0.0 https://github.com/alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

middleware psr-7 routing router psr-15

25/03 2018

1.0.2

1.0.2.0 https://github.com/alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

middleware psr-7 routing router psr-15

25/03 2018

1.0.1

1.0.1.0 https://github.com/alexpts/php-psr15-routing

Middleware routing compatible with the PSR-7 and PSR-15

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

middleware psr-7 routing router psr-15