Skip to main content

Announcing Pathfinder v0.4.0

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Peter Hildenbrand

In our attempt to convert parts of our own internal company framework into a set of open-source components we did not find a routing package that was fully PSR-7 compatible and was able to also generate uris based on the routing definitions. Initially the routing component was part of our Adroit middleware, a middleware focused on PSR-7 as well as the ADR pattern. During our attempt to turn Adroit into a (micro) web framework called Adrenaline we also extracted the routing component into a separate package.

Routes in Pathfinder are implemented immutable an can be built via the RouteBuilder helper:

use bitExpert\Pathfinder\RouteBuilder;
use bitExpert\Pathfinder\Matcher\NumericMatcher;

RouteBuilder::route()
->get('/')
->to('home')
->build();

RouteBuilder::route()
->from('/user')
->accepting('POST')
->accepting('PUT')
->to('userAction')
->build();

Routes support so-called Matchers which can ensure that your route parameters match given criterias, e.g. checking that a given id contains only digits:

RouteBuilder::route()
->get('/user/[:userId]')
->to('userAction')
->ifMatches('userId', new NumericMatcher())
->build();

Last, but not least Pathfinder comes with middleware support. The routing middleware will use the given router to match the request and will set the routing result as value of the request attribute named 'routingResult'.

use bitExpert\Pathfinder\Route;
use bitExpert\Pathfinder\Psr7Router;
use bitExpert\Pathfinder\Middleware\BasicRoutingMiddleware;

$router = new Psr7Router();

$routingMiddleware = new BasicRoutingMiddleware($router, 'routingResult');