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. [API Development](/categories/api)
4. /
5. shadowhand/either-way

AbandonedArchivedLibrary[API Development](/categories/api)

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

A functional route dispatcher

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

Since Mar 17Pushed 9y 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 3w 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 52% 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

3385d 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

[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)
