PHPackages                             91ahmed/routelite - 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. 91ahmed/routelite

ActiveLibrary[Framework](/categories/framework)

91ahmed/routelite
=================

A lightweight PHP routing library

v1.0(5mo ago)00MITPHPPHP &gt;=7.0

Since Dec 5Pushed 4mo agoCompare

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

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

Routelite
=========

[](#routelite)

Routelite is a lightweight **PHP** routing library for building flexible and maintainable web applications.
It supports route parameters, middlewares, route groups, prefixes, and multi-language URLs.

---

Features
--------

[](#features)

- Supports **GET** and **POST** routes.
- Route-specific, group, and global **Middleware** support.
- Route parameters with **Regex validation**.
- **Prefix** support for route groups or individual routes.
- Multi-language URL support.
- Custom **404 Not Found** handling.
- **Singleton** pattern to ensure only one instance.
- Ability to **remove unwanted text** from URLs before processing.

---

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

[](#installation)

You can install Routelite manually or via Composer:

```
composer require 91ahmed/routelite
```

Use it in your project:

```
use Router\Routelite;

$route = Routelite::collect();
```

---

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

[](#basic-usage)

### 1. Defining a simple route

[](#1-defining-a-simple-route)

```
$route->get('/', 'Controller\HomeController@index')->add();
$route->post('/submit', 'Controller\FormController@submit')->add();
```

### 2. Route parameters with regex validation

[](#2-route-parameters-with-regex-validation)

```
$route->get('/user/profile', 'Controller\UserController@profile')
      ->params(['id', 'username'])
      ->where('id', '/^[0-9]+$/')
      ->where('username', '/^[a-zA-Z0-9]+$/')
      ->add();
```

### 3. Using Middleware

[](#3-using-middleware)

- **Route-specific middleware:**

```
$route->get('/dashboard', 'Controller\Dashboard@index')
      ->middleware(['auth', 'log'])
      ->add();
```

- **Group middleware:**

```
$route->middlewareGroup(['auth'], function ($route) {
    $route->get('/users/all', 'Controller\UserController@index')->add();
});
```

- **Global middleware for all routes:**

```
$route->middlewareGlobal(['session']);
```

---

### 4. Route Groups and Prefixes

[](#4-route-groups-and-prefixes)

```
$route->prefixGroup('dashboard', function ($route) {
    $route->middlewareGroup(['auth'], function ($route) {
        $route->get('/users/all', 'Controller\UserController@index')->add();
        $route->get('/home', 'Controller\HomeController@home')->add();
    });
});
```

- All routes inside the `dashboard` prefix group will start with `/dashboard/...`.
- Middleware `auth` is applied to all routes inside the middleware group.

---

### 5. Multi-language support

[](#5-multi-language-support)

```
$route->setLanguage(['ar', 'en']);
```

- The first segment of the URL will be treated as the language:

    - `/ar/dashboard` → Arabic
    - `/en/dashboard` → English

---

### 6. Removing unwanted text from URLs

[](#6-removing-unwanted-text-from-urls)

```
$route->remove('Unwanted Word');
```

- The `remove()` method allows you to filter out specific parts of the URL before route processing.
    This is especially useful in development environments, like when working on `localhost`, where your project might be inside a subfolder.

---

### 7. Handling 404 Not Found

[](#7-handling-404-not-found)

```
$route->notFound(function () {
    exit('404 Not Found Page');
});
```

- Executes the callback if no matching route is found or there is a parameter error.

---

### 8. Listing all routes

[](#8-listing-all-routes)

```
$allRoutes = $route->getRoutes();
print_r($allRoutes);
```

---

### 9. Rendering Routes

[](#9-rendering-routes)

After defining all your routes, you **must** call the `render()` method to process the current request and execute the matching route:

```
$route->render();
```

- `render()` will match the current URL against all defined routes.
- It executes the associated **controller action** if a match is found.
- If no match is found, you can handle it using `notFound()`:

```
$route->notFound(function () {
    exit('404 Not Found Page');
});
```

> **Important:** Always call `render()` **after all route definitions**. Without it, no routes will be processed.

---

Full Example
------------

[](#full-example)

```
use Router\Routelite;

$route = Routelite::collect();

$route->middlewareGlobal(['session']);

$route->setLanguage(['ar', 'en']);

$route->prefixGroup('dashboard', function ($route) {
    $route->middlewareGroup(['auth'], function ($route) {
        $route->get('/users/all/', 'Controller\HomeController@index')
              ->params(['id', 'username'])
              ->where('id', '/^[0-9]+$/')
              ->where('username', '/^[a-zA-Z0-9]+$/')
              ->add();

        $route->get('/home/', 'Controller\HomeController@home')->add();
    });
});

$route->get('/', 'Controller\HomeController@index')->params(['lang'])->middleware(['auth'])->add();
$route->get('/admin', 'Controller\HomeController@admin')->params(['id'])->add();
$route->post('/users', 'Controller\HomeController@admin')->add();

$route->render();

$route->notFound(function () {
    exit('404 Not Found Page');
});
```

---

Important Notes
---------------

[](#important-notes)

- Middleware names must contain only letters, numbers, underscores, or valid namespaces.
- All middleware classes must implement a `handle()` method.
- Magic methods in controllers (e.g., `__construct`, `__call`) are **not allowed**.
- Middleware execution order: **Global → Group → Route**.
- Always use `Routelite::collect()` to get the same instance. Do not create a new instance manually.
- `setLanguage([...])` should be called before defining routes that depend on language.
- When using `params([...])`, the order of parameter names must match their order in the URL.
- The `handle()` method in middleware must return **true** to continue or **false** to stop execution.
- After defining all routes, you **must** call `render()` to execute the matching route. Without `render()`, no routes will be processed.

---

License
-------

[](#license)

MIT License

---

> **Routelite** simplifies route management in PHP projects with full support for parameters, middleware, groups, prefixes, and multi-language URLs.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance74

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity29

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

157d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/724035a53c25fe6db7725e748aa9bf0a773970f53d395db231c18855bb8dd520?d=identicon)[91ahmed](/maintainers/91ahmed)

---

Top Contributors

[![91ahmed](https://avatars.githubusercontent.com/u/44722367?v=4)](https://github.com/91ahmed "91ahmed (10 commits)")

---

Tags

php-routephp-routelitephp-routerphp-router-libraryphp-router-standalonephp-routingrouteroute-phprouteliterouter

### Embed Badge

![Health badge](/badges/91ahmed-routelite/health.svg)

```
[![Health](https://phpackages.com/badges/91ahmed-routelite/health.svg)](https://phpackages.com/packages/91ahmed-routelite)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M257](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M593](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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