PHPackages                             websitesql/router - 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. websitesql/router

ActiveLibrary

websitesql/router
=================

Router component for WebsiteSQL framework

v1.0.0(1y ago)02MITPHPPHP ^8.0

Since Apr 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/websitesql/router)[ Packagist](https://packagist.org/packages/websitesql/router)[ RSS](/packages/websitesql-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

WebsiteSQL Router
=================

[](#websitesql-router)

A lightweight, flexible routing library for PHP applications that extends the functionality of League\\Route and League\\Container while adding a custom API strategy for consistent API responses.

Overview
--------

[](#overview)

WebsiteSQL Router is built on top of the following packages:

- [League\\Route](https://route.thephpleague.com/) - Fast routing and dispatcher
- [League\\Container](https://container.thephpleague.com/) - Dependency injection container

This library extends these components and provides a custom ApiStrategy to standardize API responses across your application.

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

[](#installation)

Install via Composer:

```
composer require websitesql/router
```

Basic Usage
-----------

[](#basic-usage)

```
use WebsiteSQL\Router\Router;
use WebsiteSQL\Router\Container;
use WebsiteSQL\Router\Strategy\ApiStrategy;
use WebsiteSQL\Router\Factory\ResponseFactory;

// Create container & router
$router = new Router();
$container = new Container();

// Create the strategy
$responseFactory = new ResponseFactory();
$strategy = new ApiStrategy($responseFactory);
$strategy->setContainer($container);
$strategy->setCorsOptions([
	'origin' => ['https://example.com'],
	'methods' => ['GET', 'POST', 'PUT', 'DELETE'],
	'headers.allow' => ['Content-Type', 'Authorization'],
	'headers.expose' => ['Etag'],
	'credentials' => true,
	'cache' => 86400
]);
$router->setStrategy($strategy);

// Define routes
$router->get('/users', 'UserController::listUsers');
$router->post('/users', 'UserController::createUser');

// Dispatch the request
$response = $router->dispatch($request);
```

Features
--------

[](#features)

### Extended Router

[](#extended-router)

The Router class extends League\\Route's Router with additional functionality:

- Simplified API route definitions
- Automatic content negotiation
- Configurable middleware application
- Enhanced error handling

### Extended Container

[](#extended-container)

The Container class extends League\\Container to provide:

- Automatic controller resolution
- Simplified service registration
- Integration with router components

### Custom ApiStrategy

[](#custom-apistrategy)

The ApiStrategy standardizes how API responses are formatted:

```
// Example controller using ApiStrategy
public function getUser(ServerRequestInterface $request): array
{
    $userId = $request->getAttribute('id');
    $user = $this->userRepository->find($userId);

    // Return data as array - ApiStrategy will convert to proper response
    return ['data' => $user];
}
```

Benefits of the ApiStrategy:

- Consistent JSON response structure
- Automatic status code handling
- Standard error formatting
- Content negotiation
- CORS support

Configuration
-------------

[](#configuration)

### Customizing ApiStrategy

[](#customizing-apistrategy)

```
use WebsiteSQL\Router\Strategy\ApiStrategy;

$strategy = new ApiStrategy();
$strategy->setContainer($container);

// Configure CORS
$strategy->setCorsOptions([
    'origin' => ['https://example.com'],
    'methods' => ['GET', 'POST', 'PUT', 'DELETE'],
    'headers.allow' => ['Content-Type', 'Authorization'],
    'headers.expose' => ['Etag'],
    'credentials' => true,
    'cache' => 86400
]);

$router->setStrategy($strategy);
```

Error Handling
--------------

[](#error-handling)

The ApiStrategy automatically converts exceptions to appropriate HTTP responses:

- `NotFoundException` → 404 Not Found response
- `UnauthorizedException` → 401 Unauthorized response
- `ForbiddenException` → 403 Forbidden response
- Other exceptions → 500 Internal Server Error response

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance47

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

399d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/280e4b985f922abd667a75c49aee0c176202dcbf84464fd50de0cd9328092e60?d=identicon)[alantiller](/maintainers/alantiller)

---

Top Contributors

[![alantiller](https://avatars.githubusercontent.com/u/26198238?v=4)](https://github.com/alantiller "alantiller (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/websitesql-router/health.svg)

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42155.0k19](/packages/rareloop-lumberjack-core)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5016.9k1](/packages/simplesamlphp-simplesamlphp-module-oidc)

PHPackages © 2026

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