2017 © Pedro Peláez
 

library php-routing

Simple router compatible with the PSR-7

image

alexpts/php-routing

Simple router compatible with the PSR-7

  • Tuesday, March 13, 2018
  • by alexpts
  • Repository
  • 1 Watchers
  • 3 Stars
  • 103 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

php-routing

SensioLabsInsight, (*1)

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

Простой роутер с поддержкой PSR-7 и middelware на уровне роута., (*3)

Возможности

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

Простой роутинг

use PTS\Routing\Route;
use PTS\Routing\CollectionRoute;
use PTS\Routing\Matcher;
use PTS\Routing\RouteService;
use Psr\Http\Message\RequestInterface;

$route = new Route('/', function() {
    return ['response' => 'data'];
});
$collection = new CollectionRoute();
$collection->add('main', $route);
$matcher = new Matcher(new RouteService());

$activeRoute = $matcher->match($collection, '/')->current();
$response = $activeRoute($request); // PSR-7 request

Захват параметров из url

Захваченные параметры могут быть переданы в качестве аргументов в обработчик. Параметры начинающиеся с символа _ игнорируются. Они нужны для технических нужд., (*4)

use PTS\Routing\Route;
use PTS\Routing\CollectionRoute;
use PTS\Routing\Matcher;
use PTS\Routing\RouteService;
use Psr\Http\Message\RequestInterface;

$route = new Route('/users/{userId}/', function($userId) {
    return $userId;
});
$route->pushMiddleware(new CallWithMatchParams);

$collection = new CollectionRoute();
$collection->add('user', $route);
$matcher = new Matcher(new RouteService());

$activeRoute = $matcher->match($collection, '/users/4/')->current();

The Versions

13/03 2018

dev-master

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

Simple router compatible with the PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

psr-7 router

05/09 2017

1.0.0

1.0.0.0 https://github.com/alexpts/php-routing

Simple router compatible with the PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

psr-7 router

08/04 2017

1.0.0-RC3

1.0.0.0-RC3 https://github.com/alexpts/php-routing

Simple router compatible with the PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

psr-7 router

01/11 2016

1.0.0-RC2

1.0.0.0-RC2 https://github.com/alexpts/php-routing

Simple router compatible with the PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

psr-7 router

20/04 2016

1.0.0-RC1

1.0.0.0-RC1 https://github.com/alexpts/php-routing

Simple router compatible with the PSR-7

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar alexpts

psr-7 router