PHPackages                             bitexpert/pathfinder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bitexpert/pathfinder

AbandonedArchivedLibrary[API Development](/categories/api)

bitexpert/pathfinder
====================

PSR-7 compatible routing component

v0.5.0(9y ago)61.2k↓84.6%3[1 issues](https://github.com/bitExpert/pathfinder/issues)1Apache-2.0PHPPHP ^7.0

Since Nov 29Pushed 8y ago2 watchersCompare

[ Source](https://github.com/bitExpert/pathfinder)[ Packagist](https://packagist.org/packages/bitexpert/pathfinder)[ RSS](/packages/bitexpert-pathfinder/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (10)Versions (14)Used By (1)

bitexpert/pathfinder
====================

[](#bitexpertpathfinder)

A PHP routing component.

[![Build Status](https://camo.githubusercontent.com/cef6d35d881e28a15ad0ed987776331947ba66a7d07c69589d8e45ef5491339b/68747470733a2f2f7472617669732d63692e6f72672f6269744578706572742f7061746866696e6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bitExpert/pathfinder)[![Coverage Status](https://camo.githubusercontent.com/1a7d902714fd22acd224e9c45d24def647fde192b666c86ece8b821d0720148f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6269744578706572742f7061746866696e6465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bitExpert/pathfinder?branch=master)

Router
------

[](#router)

The router is responsible for resolving the target from the given route as well building an uri for a given route identifier (and it`s parameters). Using the [Psr7Router](src/bitExpert/Pathfinder/Psr7Router.php) is pretty easy:

```
$router = new \bitExpert\Pathfinder\Psr7Router();
$router->setRoutes(
    [
        new Route(['GET'], '/', 'index'),
        new Route(['GET'], '/question/[:title]_[:id]', 'question'),
        new Route(['GET', 'POST'], '/editquestion', 'editquestion')
    ]
);
```

Routes
------

[](#routes)

[Routes](src/bitExpert/Pathfinder/Route.php) in Pathfinder are implemented immutual. You may define your routes by creating a route instance directly as shown above or using the [RouteBuilder](src/bitExpert/Pathfinder/RouteBuilder.php) for convenience (recommended):

```
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();

RouteBuilder::route()
    ->get('/')
    ->to(function () {

    })
    ->named('home')
    ->build();

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

Customizing the RouteBuilder
----------------------------

[](#customizing-the-routebuilder)

In case you need some special route classes for your application, you may configure the [RouteBuilder](src/bitExpert/Pathfinder/RouteBuilder.php) to use your custom route class instead of [Route](src/bitExpert/Pathfinder/Route.php) either for a particular route:

```
$route = RouteBuilder::route(MyCustomRoute::class)
    ->get('/')
    ->to('home')
    ->build();

$route->doCustomStuffDefinedInYourClass();
```

or globally as default class to use:

```
RouteBuilder::setDefaultRouteClass(MyCustomRoute::class);

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

$route->doCustomStuffDefinedInYourClass();
```

Matchers
--------

[](#matchers)

[Matchers](src/bitExpert/Pathfinder/Matcher/Matcher.php) are used to ensure that your route params match given criteria such as digits only:

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

You may add several matchers for one param, just by adding them via:

```
RouteBuilder::route()
    ->get('/user/[:userId]')
    ->to('userAction')
    ->ifMatches('userId', new NumericMatcher())
    ->ifMatches('userId', new MyCustomMatcher())
    ->ifMatches('userId', function ($value) {

    })
    ->build();
```

Middleware
----------

[](#middleware)

You may use the [BasicRoutingMiddleware](src/bitExpert/Pathfinder/Middleware/BasicRoutingMiddleware.php) to integrate Pathfinder into your PSR-7 compatible project:

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

$router = new Psr7Router();
$router->addRoute(RouteBuilder::route()->get('/')->to('home')->build());

// 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' for further use
$routingMiddleware = new BasicRoutingMiddleware($router, 'routingResult');
```

Errors
------

[](#errors)

The [Psr7Router](src/bitExpert/Pathfinder/Psr7Router.php) does not throw an Exception if the request doesn't match any route. It will still return a [RoutingResult](src/bitExpert/Pathfinder/RoutingResult.php) returning true when calling $routingResult-&gt;failed(); You may receive the failure reason by calling $routingResult-&gt;getFailure() which will give you information about the failure reason and an optional route which could have matched, but didn't fulfill all criteria:

```
use bitExpert\Pathfinder\Psr7Router;
use bitExpert\Pathfinder\RouteBuilder;
use Zend\Diactoros\ServerRequest;
use bitExpert\Pathfinder\Matcher\NumericMatcher;

$router = new Psr7Router();

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

$orderUpdateRoute = RouteBuilder::route()
    ->put('/order/[:orderId]')
    ->to('updateOrder')
    ->ifMatches('id', new NumericMatcher())
    ->build();

$router->setRoutes([$homeRoute, $orderUpdateRoute]);

// Not found example
$request = new ServerRequest([], [], '/users', 'GET');
$result = $router->match($request);

$result->failed(); // -> true
$result->getFailure(); // -> RoutingResult::FAILED_NOT_FOUND
$result->hasRoute(); // -> false

// Method not allowed example
$request = new ServerRequest([], [], '/order/1', 'GET');
$result = $router->match($request);

$result->failed(); // -> true
$result->getFailure(); // -> RoutingResult::FAILED_METHOD_NOT_ALLOWED
$result->hasRoute(); // -> true
$result->getRoute(); // -> $orderUpdateRoute

// BadRequest example
$request = new ServerRequest([], [], '/order/abc', 'PUT');
$result = $router->match($request);

$result->failed(); // -> true
$result->getFailure(); // -> RoutingResult::FAILED_BAD_REQUEST
$result->hasRoute(); // -> true
$result->getRoute(); // -> $orderUpdateRoute
```

License
-------

[](#license)

Pathfinder is released under the Apache 2.0 license.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~46 days

Recently: every ~80 days

Total

8

Last Release

3535d ago

PHP version history (2 changes)0.1.0PHP ^5.5|^7.0

v0.5.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1adf0ab660536efce10aeb97f0c90ec881110b64fbd23429fa945190df0def56?d=identicon)[shochdoerfer](/maintainers/shochdoerfer)

---

Top Contributors

[![shochdoerfer](https://avatars.githubusercontent.com/u/596449?v=4)](https://github.com/shochdoerfer "shochdoerfer (53 commits)")[![dropdevcoding](https://avatars.githubusercontent.com/u/3219267?v=4)](https://github.com/dropdevcoding "dropdevcoding (48 commits)")

---

Tags

pathfinderphpphp7psr-7routerrouting

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bitexpert-pathfinder/health.svg)

```
[![Health](https://phpackages.com/badges/bitexpert-pathfinder/health.svg)](https://phpackages.com/packages/bitexpert-pathfinder)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69634.4M144](/packages/algolia-algoliasearch-client-php)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k33](/packages/neuron-core-neuron-ai)[n1ebieski/ksef-php-client

PHP API client that allows you to interact with the API Krajowego Systemu e-Faktur

8754.6k](/packages/n1ebieski-ksef-php-client)[trycourier/courier

Courier PHP SDK

15654.8k](/packages/trycourier-courier)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
