Download the PHP package sethrensei/ren-router without Composer
On this page you can find all versions of the php package sethrensei/ren-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sethrensei/ren-router
More information about sethrensei/ren-router
Files in sethrensei/ren-router
Package ren-router
Short Description Secure lightweight PHP router with RBAC, CSRF and HTTP error handling
License MIT
Informations about the package ren-router
RenRouter
RenRouter is a modern, lightweight and secure PHP micro-router — designed to be the routing core of a custom framework or as a standalone HTTP layer for projects that don't need a full framework.
It provides clean HTTP orchestration (routing, dispatching, views, error handling), declarative security (authentication and roles), pluggable template engines (PHP or Twig), and URL extension spoofing for stack obfuscation.
✨ Key Features
- HTTP routing powered by AltoRouter
- Fluent, readable route registration with
get(),post(),route()shortcuts - RouterFactory — clean builder pattern, no positional
nullarguments - Pluggable template engines: native PHP files or Twig (Symfony-style)
- URL extension spoofing — serve
/contact.htmlor/about.aspxwhile routes stay clean internally - Declarative route protection: authentication and role-based access control
- Centralized HTTP exception handling (401, 403, 404, 500) with dedicated error views
Controller@methodstring target support alongside callables and view names- AbstractController base class with rendering, redirects, JSON responses, flash messages and request helpers
- PSR-3 logger support (optional)
- PHP 8.1+ with
readonlyproperties andneverreturn types
🧱 Architecture
🚀 Quick Start
1. Install
2. Bootstrap (PHP templates)
3. Bootstrap (Twig)
🔀 Route Registration
| Method | Signature | Use case |
|---|---|---|
get() |
get(uri, target, name, options) |
Single GET route |
post() |
post(uri, target, name, options) |
Single POST route |
route() |
route(uri, target, method, name, options) |
Any method or GET\|POST |
Targets can be:
AltoRouter patterns are supported in URIs:
🔐 Security & Authorization
Security is declared at route level, not inside controllers.
| Option | Type | Behaviour |
|---|---|---|
auth |
bool |
Redirects to the security route if not authenticated |
roles |
string\|string[] |
Throws 403 if no matching role is found |
Automatically thrown exceptions:
| Situation | Exception | HTTP Code |
|---|---|---|
| Not authenticated | UnauthorizedHttpException |
401 |
| Wrong role | ForbiddenHttpException |
403 |
| No matching route | NotFoundHttpException |
404 |
| Any other error | HttpException / caught Throwable |
500 |
Auth helper
🎮 Controllers
Extend AbstractController for instant access to all response helpers.
AbstractController API
| Category | Method | Description |
|---|---|---|
| Guards | requireAuth(?Router) |
Redirect to login if not authenticated |
requireRole(roles, ?Router) |
Requires auth + matching role | |
denyUnless(bool, message) |
Throws 403 when condition is false | |
notFound(message): never |
Throws 404 immediately | |
| Rendering | render(view, data, ?Router) |
Renders via the template engine |
renderPartial(view, data, ?Router): string |
Returns rendered HTML as string | |
| Redirects | redirectToRoute(name, params, status, ?Router) |
Named route redirect |
redirect(url, status, ?Router) |
Raw URL redirect | |
| JSON | json(data, status): never |
JSON response + exit |
jsonError(message, status, extra): never |
{error, message, code} + exit |
|
| Flash | flash(type, message) |
Write flash to session |
flashSuccess(message) |
Shorthand for type success |
|
flashError(message) |
Shorthand for type error |
|
getFlash(type): array |
Read + clear one type | |
getAllFlash(): array |
Read + clear all types | |
| Request | input(key, default, from) |
Read from POST/GET/both |
postData(only): array |
All POST, optionally filtered | |
isMethod(method): bool |
Check HTTP method | |
isAjax(): bool |
XHR / JSON Accept detection |
🌐 Twig Integration
TwigEngine mirrors Symfony's Twig integration exactly.
These functions are available in every template automatically:
| Twig function | PHP equivalent | Example output |
|---|---|---|
path('route', {id:1}) |
Router::path() |
/contact.html |
url('route', {id:1}) |
Router::url() |
https://example.com/contact.html |
asset('css/app.css') |
Router::asset() |
https://example.com/css/app.css |
route_exists('name') |
Router::hasRoute() |
true / false |
For custom extensions and globals:
🎭 URL Extension Spoofing
Confuse security scanners and bots by exposing a fake tech stack:
Generated URLs follow the same rule:
The extension is stripped from incoming requests before matching — your route definitions never need to change.
❗ Error Handling
Errors are caught centrally by the router. In production, dedicated view files are rendered:
The $exception and $code variables are available inside error views.
In development (APP_ENV=DEV), the raw exception message and stack trace are printed as plain text.
You can also map error codes to named routes:
🔗 URL Generation
📦 Requirements
| PHP | ≥ 8.1 |
| AltoRouter | composer require altorouter/altorouter |
| Twig | composer require twig/twig |
| Symfony Dotenv | composer require symfony/dotenv |
| HTMLPurifier | composer require ezyang/htmlpurifier" |
| PSR-3 logger, HTTP message and factory | any PSR-3 compatible package |
🎯 Philosophy
RenRouter is built around three principles:
- Clarity over magic — every behaviour is explicit and traceable
- Security by default — auth and roles declared at the route, not buried in controllers
- A solid, extensible core — swap the template engine, add a logger, override any component
It is not a framework. It is a reliable foundation to build one.
📄 License
MIT — free to use, modify and distribute.
All versions of ren-router with dependencies
psr/log Version ^3.0
psr/http-message Version ^2.0
psr/http-factory Version ^1.1
symfony/dotenv Version ^7.4
ezyang/htmlpurifier Version ^4.19
twig/twig Version ^3.27