PHPackages                             studiow/league-route-conversionstrategy - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. studiow/league-route-conversionstrategy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

studiow/league-route-conversionstrategy
=======================================

A smart conversion strategy for league/route

01PHP

Since Sep 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/studiowbe/league-route-conversionstrategy)[ Packagist](https://packagist.org/packages/studiow/league-route-conversionstrategy)[ RSS](/packages/studiow-league-route-conversionstrategy/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

league-route-conversionstrategy
===============================

[](#league-route-conversionstrategy)

A smart conversion strategy for league/route. It allows you to return pretty much anything you want from your controllers/handlers.

**Note** The strategy offers a convenient way to convert multiple types of return values to ResponseInterface objects. Of course you can still return a ResponseInterface object for maximum control.

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

[](#installation)

The recommended way to install the package is composer:

```
composer require studiow/league-route-conversionstrategy
```

To use it in your code, use it like any other StrategyInterface:

```
$router = new \League\Route\Router();
$strategy = new \Studiow\LeagueRoute\Strategy\ConversionStrategy(
    new \Studiow\LeagueRoute\Strategy\Convertor\HtmlConvertor($responseFactory)
);
$router->setStrategy($strategy);
```

Conversions
-----------

[](#conversions)

The package comes with the following conversions bundled:

### HtmlConvertor

[](#htmlconvertor)

This convertor will convert any text to a text/html response

```
$router = new \League\Route\Router();
$strategy = new \Studiow\LeagueRoute\Strategy\ConversionStrategy(
    new \Studiow\LeagueRoute\Strategy\Convertor\HtmlConvertor($responseFactory)
);
$router->setStrategy($strategy);

//we can now return text
$router->get('/text', function(){
    return 'Hello world';
});
```

### JsonConvertor

[](#jsonconvertor)

This convertor will convert any array or object to an application/json response

```
$router = new \League\Route\Router();
$strategy = new \Studiow\LeagueRoute\Strategy\ConversionStrategy(
    new \Studiow\LeagueRoute\Strategy\Convertor\JsonConvertor($responseFactory)
);
$router->setStrategy($strategy);

//we can now return arrays
$router->get('/array', function(){
    return ['foo'=>'bar'];
});

//or objects (that may or may not implement JsonSerializable
$router->get('/object', function(){
     return new ArrayObject(['foo'=>'bar']);
});
```

### ConvertorCollection

[](#convertorcollection)

This convertor allows you to have multiple conversions. The first one that can be used will be used:

```
$router = new \League\Route\Router();

$convertors = new \Studiow\LeagueRoute\Strategy\Convertor\ConvertorCollection([
   new \Studiow\LeagueRoute\Strategy\Convertor\JsonConvertor($responseFactory),
   new \Studiow\LeagueRoute\Strategy\Convertor\HtmlConvertor($responseFactory)
]);

$strategy = new \Studiow\LeagueRoute\Strategy\ConversionStrategy($convertors);
$router->setStrategy($strategy);

//this will be handled by the HtmlConvertor
$router->get('/text', function () {
   return 'Hello world';
});

//this will be handled by the JsonConvertor
$router->get('/array', function () {
   return ['foo' => 'bar'];
});

//this will also be handled by the JsonConvertor
$router->get('/object', function () {
   return new ArrayObject(['foo' => 'bar']);
});

//you can always still return a ResponseInterface object. This will be unmodified:
$router->get('/full-response', function () {
   return new Response(...)
});
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b57a4311f92e06e73f6c646344a069d0088747f22e420a583f91bd3e6ab1729?d=identicon)[studiowbe](/maintainers/studiowbe)

---

Top Contributors

[![willemwollebrants](https://avatars.githubusercontent.com/u/916958?v=4)](https://github.com/willemwollebrants "willemwollebrants (5 commits)")

### Embed Badge

![Health badge](/badges/studiow-league-route-conversionstrategy/health.svg)

```
[![Health](https://phpackages.com/badges/studiow-league-route-conversionstrategy/health.svg)](https://phpackages.com/packages/studiow-league-route-conversionstrategy)
```

PHPackages © 2026

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