alexpts / php-routing
Simple router compatible with the PSR-7
Installs: 120
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alexpts/php-routing
Requires
- php: >=7.1
 - alexpts/php-tools: ^3.0
 - psr/http-message: ^1.0.1
 
Requires (Dev)
- phpunit/phpunit: ^6.2
 - zendframework/zend-diactoros: ^1.5
 
This package is auto-updated.
Last update: 2025-10-15 04:13:33 UTC
README
Простой роутер с поддержкой PSR-7 и middelware на уровне роута.
Возможности
- Простой захват параметров из 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
Захваченные параметры могут быть переданы в качестве аргументов в обработчик.
Параметры начинающиеся с символа _ игнорируются. Они нужны для технических нужд.
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();