PHPackages                             jinexus-framework/jinexus-route - 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. [Framework](/categories/framework)
4. /
5. jinexus-framework/jinexus-route

ActiveComponent[Framework](/categories/framework)

jinexus-framework/jinexus-route
===============================

Route component from JiNexus Framework

1.0.0(7y ago)0381BSD-3-ClausePHPPHP ^5.6 || ^7.0CI passing

Since Dec 10Pushed 2w ago1 watchersCompare

[ Source](https://github.com/jinexus-framework/jinexus-route)[ Packagist](https://packagist.org/packages/jinexus-framework/jinexus-route)[ Docs](https://github.com/jinexus-framework/jinexus-route)[ RSS](/packages/jinexus-framework-jinexus-route/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (2)DependenciesVersions (5)Used By (1)

JiNexus Route
=============

[](#jinexus-route)

`JiNexus Route` provides simple route matching and access to every registered route in an application, together with a redirect helper, for jinexus-mvc applications.

A `Route` holds a name-keyed table of route definitions, derives the current request URI from `$_SERVER`, and matches it against that table. A `Redirect` sends a `Location` header for a named route and terminates the request.

- Documentation:
- Issues:

Requirements
------------

[](#requirements)

- PHP `^8.5`

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

[](#installation)

Install via [Composer](https://getcomposer.org/):

```
composer require jinexus-framework/jinexus-route
```

Usage
-----

[](#usage)

### Registering routes

[](#registering-routes)

A route table is an array keyed by the route name. Each entry needs a `route` key holding the URI; any other keys are yours to use and are returned untouched on a match.

```
use JiNexus\Route\Route\Route;
use JiNexus\Route\Route\Factory\RouteFactory;
use JiNexus\Route\Redirect\Redirect;

// Via the factory (builds and wires a Redirect for you)...
$route = RouteFactory::build();

// ...or explicitly.
$route = new Route(new Redirect());

$route->setRoutes([
    'home'  => ['route' => '/',         'controller' => HomeController::class],
    'about' => ['route' => '/about-us', 'controller' => AboutController::class],
    'user'  => ['route' => '/user',     'controller' => UserController::class],
]);

$route->getRoutes();   // the full table
$route->setRoutes();   // called with no argument, resets to []
```

### Matching the current request

[](#matching-the-current-request)

```
// Match an explicit URI.
$route->getMatchRoute([], '/about-us');
// ['about' => ['route' => '/about-us', 'controller' => AboutController::class]]

// Omit the URI to match against the current request.
$route->getMatchRoute();

// No match returns an empty array.
$route->getMatchRoute([], '/nope');   // []
```

A match returns the **whole entry, keyed by its route name**. Matching stops at the first hit, so if two names share a URI, the earlier one wins.

You can also match against a table passed in directly, without registering it. A supplied table takes precedence; an empty one falls back to the registered routes:

```
$route->getMatchRoute(['about' => ['route' => '/about-us']], '/about-us');
// ['about' => ['route' => '/about-us']]
```

### Resolving a route's URI by name

[](#resolving-a-routes-uri-by-name)

```
$routes = [
    'home' => ['route' => '/'],
    'user' => ['route' => '/user'],
];

$route->getRouteUri('home', $routes);              // '/'
$route->getRouteUri('user/profile/42', $routes);   // '/user' — only the first segment is looked up
$route->getRouteUri('missing', $routes);           // throws RouteException

// Omit the table to resolve against the registered routes.
$route->setRoutes($routes);
$route->getRouteUri('home');                       // '/'
```

`getRouteUri()` follows the same rule as `getMatchRoute()`: a supplied `$routes` table wins, and an empty one falls back to whatever `setRoutes()` registered. It throws a `RouteException` when the name is found in neither.

### Deriving the request URI

[](#deriving-the-request-uri)

`getUri()` strips the directory the front controller lives in, drops the query string, and normalizes the surrounding slashes:

```
// SCRIPT_NAME = /app/public/index.php
// REQUEST_URI = /app/public/user/42?ref=nav
$route->getUri();   // '/user/42'
```

`SCRIPT_NAME``REQUEST_URI``getUri()``/index.php``/``/``/index.php``/about-us/``/about-us``/index.php``/search?q=a/b``/search``/app/public/index.php``/app/public/``/``/app/public/index.php``/app/public/user/42``/user/42`This reads `$_SERVER['SCRIPT_NAME']` and `$_SERVER['REQUEST_URI']` directly, so both must be present.

### Redirecting

[](#redirecting)

```
use JiNexus\Route\Redirect\Redirect;
use JiNexus\Route\Redirect\Factory\RedirectFactory;

$redirect = RedirectFactory::build();   // or: new Redirect()

$redirect->setRoutes([
    'home'  => ['route' => '/'],
    'about' => ['route' => '/about-us'],
]);

$redirect->toRoute('about');         // 302 Location: /about-us, then exits
$redirect->toRoute('about', true);   // 301 Location: /about-us, then exits
```

`toRoute()` throws a `RouteException` when the name is empty or unregistered and skips the header if headers have already been sent. It terminates the request either way, so nothing after the call runs.

The redirect a `Route` was constructed with is reachable from it:

```
$route->redirect;         // the RedirectInterface
$route->getRedirect();    // same, through AbstractBase::__call()
```

### Magic getters and setters

[](#magic-getters-and-setters)

`AbstractBase::__call()` resolves `getX()`/`setX()` against **public** properties only. Setters are fluent. Anything it cannot resolve — a protected property, an unknown property, or a method that isn't a `get`/`set` prefix — throws a `RouteException`:

```
$route->getRedirect();              // reads the public $redirect
$route->setRedirect($otherOne);     // returns $route, so it chains

$redirect->getRoutes();             // throws: $routes is protected
// RouteException: Not implemented: JiNexus\Route\Redirect\Redirect::routes
```

### Error handling

[](#error-handling)

Package-level failures throw `JiNexus\Route\RouteException` (a subclass of `\Exception`):

MessageThrown by`Route "" not found``getRouteUri()`, `toRoute()``Route name must be provided``toRoute()` with an empty name`Not implemented: ::``AbstractBase::__call()`Extending
---------

[](#extending)

`Route` and `Redirect` are deliberately empty subclasses of `AbstractRoute` and `AbstractRedirect`. Keep them that way — the public accessors are implemented with PHP property hooks over backing fields, and declaring a real property would shadow them. For IDE autocompletion, prefer `@property` PHPDoc tags over real properties.

`AbstractRedirect` exposes three `protected` seams so the terminating redirect can be tested: `headersSent()`, `sendHeader()`, and `terminate()`. Override them in a subclass to observe or intercept the redirect instead of ending the request.

Testing
-------

[](#testing)

```
composer install
composer test            # or: ./vendor/bin/phpunit
composer test:coverage   # text coverage report
composer test:testdox    # readable, per-test output
```

The suite is 52 tests at 100% line, method, and class coverage. `phpunit.dist.xml` is the committed configuration. Use `XDEBUG_MODE=off` to silence the local Xdebug notice:

```
XDEBUG_MODE=off ./vendor/bin/phpunit --testdox
```

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

[](#contributing)

Please see [CONDUCT.md](CONDUCT.md) for the code of conduct. Contributions should include tests and a `CHANGELOG.md` entry. See [AGENTS.md](AGENTS.md) for detailed build, style, and workflow conventions.

License
-------

[](#license)

BSD-3-Clause. See [LICENSE.md](LICENSE.md).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance63

Regular maintenance activity

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~0 days

Total

2

Last Release

2803d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6903966?v=4)[Jimvirle Calago](/maintainers/JiNexus)[@JiNexus](https://github.com/JiNexus)

---

Top Contributors

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

---

Tags

routejinexus

### Embed Badge

![Health badge](/badges/jinexus-framework-jinexus-route/health.svg)

```
[![Health](https://phpackages.com/badges/jinexus-framework-jinexus-route/health.svg)](https://phpackages.com/packages/jinexus-framework-jinexus-route)
```

###  Alternatives

[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

697236.2k19](/packages/pecee-simple-router)[izniburak/router

simple router class for php

23323.7k7](/packages/izniburak-router)[lesichkovm/laravel-advanced-route

Advanced route class for Laravel - restoring implicit controllers to the framework.

70149.5k2](/packages/lesichkovm-laravel-advanced-route)[ecoal95/php-router

Minimal routing library

271.0k1](/packages/ecoal95-php-router)[rosengate/exedra

Nestful route oriented PHP micro framework

142.0k1](/packages/rosengate-exedra)[developermarius/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

112.6k](/packages/developermarius-simple-router)

PHPackages © 2026

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