PHPackages                             shadowhand/either-way - 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. shadowhand/either-way

AbandonedArchivedLibrary

shadowhand/either-way
=====================

A functional route dispatcher

1.0.0(9y ago)4841MITPHPPHP &gt;=7.0

Since Mar 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/shadowhand/either-way)[ Packagist](https://packagist.org/packages/shadowhand/either-way)[ RSS](/packages/shadowhand-either-way/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

EitherWay
=========

[](#eitherway)

EitherWay combines the excellent [`FastRoute`](https://github.com/nikic/FastRoute)with [`FP-Either`](https://github.com/php-fp/php-fp-either) to create an easy to dispatch routes that resolve to class names or container identifiers.

Installation
------------

[](#installation)

```
composer require shadowhand/either-way

```

Usage
-----

[](#usage)

First, create a [PSR-7 `ServerRequestInterface`](http://www.php-fig.org/psr/psr-7/#psrhttpmessageserverrequestinterface). In this example, we will use [PSR-17 `ServerRequestFactory`](https://github.com/http-interop/http-factory).

```
$request = $serverRequestFactory->createServerRequest($_SERVER);
```

Next, create a `Dispatcher` with FastRoute:

```
$dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
    $r->get('/[{name}]', Acme\WelcomeController::class);
});
```

Now define two handlers: one to handle routing errors, and one to handle successful routing:

```
$handleError = function (int $httpStatus) use ($responseFactory): ResponseInterface {
    return $responseFactory->createResponse($httpStatus);
};
```

Note that the error value will be an HTTP status code. How this code is mapped to a response is up to you, the only requirement is that the error handler will return a PSR-7 `ResponseInterface`.

```
use EitherWay\Route;

$handleSuccess = function (Route $route) use ($container): ResponseInterface {
    $handler = $container->get($route->handler());
    $response = $handler($route->request());

    return $response;
};
```

The EitherWay `Route` contains two values: the handler string, which is either a class name or a container identifier, and the server request with route parameters attached to it.

Again, how the handler and the request get mapped to a response is up to you, the only requirement is that the handler returns a response.

### Dispatching

[](#dispatching)

Now that all everything is defined, we can execute the routing:

```
use function EitherWay\dispatch;

$response = dispatch($request, $dispatcher)
    ->either($handleError, $handleSuccess);
```

At this point, the response can modified and ultimately sent.

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

3340d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38203?v=4)[Woody Gilk](/maintainers/shadowhand)[@shadowhand](https://github.com/shadowhand)

---

Top Contributors

[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (3 commits)")

---

Tags

dispatcherfast-routefunctionalphp7psr-7

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shadowhand-either-way/health.svg)

```
[![Health](https://phpackages.com/badges/shadowhand-either-way/health.svg)](https://phpackages.com/packages/shadowhand-either-way)
```

###  Alternatives

[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k20](/packages/neuron-core-neuron-ai)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[iwechatpay/openapi

为 wechatpay/wechatpay 增加IDE提示的接口描述包。

406.7k](/packages/iwechatpay-openapi)

PHPackages © 2026

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