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

ActiveLibrary[Framework](/categories/framework)

orbiit/router
=============

A modern, lightweight PHP 8.5+ router focused on features and performance.

v1.1.0(1mo ago)017↑100%MITPHPPHP &gt;=8.5CI failing

Since Apr 14Pushed 1mo agoCompare

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

READMEChangelogDependencies (3)Versions (7)Used By (0)

Orbiit Router @Orbiit
=====================

[](#orbiit-router-orbiit)

[![PHP Version](https://camo.githubusercontent.com/8760c5726ca4cc71afaeccf4c8c8f14aa61dbcf84a4f0756d8fd0f0a1fd0e640/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e352d3838393262662e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

###### Modern, fast and type-safe. The Orbiit Router is a PHP routing component built for high-performance SaaS and Retail applications. Leverages the power of native **PHP 8.5 Attributes** to provide a clean, declarative way to manage your application's flow.

[](#modern-fast-and-type-safe-the-orbiit-router-is-a-php-routing-component-built-for-high-performance-saas-and-retail-applications-leverages-the-power-of-native-php-85-attributes-to-provide-a-clean-declarative-way-to-manage-your-applications-flow)

Moderno, rápido e tipado. O Orbiit Router é um componente de rotas PHP construído para aplicações SaaS e Varejo de alta performance. Aproveita o poder dos **Attributes nativos do PHP 8.5** para fornecer uma maneira limpa e declarativa de gerenciar o fluxo da sua aplicação.

---

Why Orbiit Router? (Por que Orbiit Router?)
-------------------------------------------

[](#why-orbiit-router-por-que-orbiit-router)

The Orbiit Router was designed to overcome the limitations of centralized routing files. Instead of managing a massive `routes.php` file, Orbiit allows you to define your infrastructure directly where the logic happens.

1. **Decentralized Logic:** Routes are defined in Controllers, making maintenance intuitive.
2. **Native PHP 8.5 Power:** Uses Attributes and Enums for a 100% type-safe experience.
3. **Onion Pipeline:** A robust middleware chain that allows pre and post-processing.

---

Highlights (Destaques)
----------------------

[](#highlights-destaques)

- **Native Attributes:** Define routes and groups directly in your controllers.
- **Onion Middleware Pipeline:** Robust execution chain for request interception.
- **High Performance:** Optimized Reflection and Regex dispatching.
- **Type Safe:** Native support for PHP 8.5 Enums and strict typing.

---

Installation (Instalação)
-------------------------

[](#installation-instalação)

Orbiit Router is available via Composer:

```
composer require orbiit/router
```

Server Configuration (Configuração do Servidor)
-----------------------------------------------

[](#server-configuration-configuração-do-servidor)

To use Orbiit Router, you must redirect all traffic to your index.php.

#### Apache (.htaccess)

[](#apache-htaccess)

```
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=/$1 [L,QSA]

```

#### Nginx

[](#nginx)

```
location / {
    try_files $uri $uri/ /index.php?route=$uri&$args;
}

```

Quick Start (Início Rápido)
---------------------------

[](#quick-start-início-rápido)

#### Define your Controller

[](#define-your-controller)

```
namespace App\Controllers;

use Orbiit\Router\Attributes\{Route, Group};
use Orbiit\Router\Enums\Method;

#[Group(prefix: '/admin', middlewares: [AuthMiddleware::class])]
class DashboardController
{
    #[Route(path: '/stats', method: Method::GET, name: 'admin.stats')]
    public function index(): string
    {
        return "Welcome to the retail dashboard!";
    }

    #[Route(path: '/user/{id}', method: Method::DELETE)]
    public function delete(int $id): string // The 'id' is automatically cast to int!
    {
        return "User {$id} deleted!";
    }
}
```

#### RESTFul Example

[](#restful-example)

```
#[Group(prefix: '/api/v1/products')]
class ProductController
{
    #[Route(path: '/', method: Method::GET)]
    public function list(): array
    {
        return ['product1', 'product2']; // List all
    }

    #[Route(path: '/', method: Method::POST)]
    public function store(): string
    {
        return "Product created successfully!";
    }

    #[Route(path: '/{id}', method: Method::PUT)]
    public function update(int $id): string
    {
        return "Product {$id} updated!";
    }

    #[Route(path: '/{id}', method: Method::DELETE)]
    public function destroy(int $id): string
    {
        return "Product {$id} removed!";
    }
}
```

**Note on HTTP Methods:** Orbiit Router supports all HTTP verbs. When using native HTML forms (which only support GET/POST), you can easily implement "Method Spoofing" by passing the intended method through a hidden field or header and injecting it into the dispatch method.

#### Implement a Middleware

[](#implement-a-middleware)

```
use Orbiit\Router\Contracts\MiddlewareInterface;

class AuthMiddleware implements MiddlewareInterface
{
    /**
     * Handle the incoming request.
     *
     * @param mixed    $request The request object or data.
     * @param callable $next The next middleware or the controller action.
     * @return mixed   The response generated.
     */
    public function handle(mixed $request, callable $next): mixed
    {
        // Example: Simple Token Validation
        $token = $request['HTTP_AUTHORIZATION'] ?? null;

        if (!$token || $token !== 'your-secret-token') {
            http_response_code(401);
            return "Unauthorized Access";
        }

        return $next($request);
    }
}
```

#### Dispatch

[](#dispatch)

```
require "vendor/autoload.php";

$router = new Orbiit\Router\Router("https://yourdomain.com");
$router->setNamespace('App\Controllers');
$router->loadController('DashboardController');

try {
    echo $router->dispatch($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
} catch (\Exception $e) {
    http_response_code(404);
    echo $e->getMessage();
}
```

🛠 Advanced Error Handling
-------------------------

[](#-advanced-error-handling)

Orbiit Router throws specialized exceptions, allowing you to catch specific errors and provide custom responses (like stylized 404 pages or JSON logs for your POS terminals).

```
use Orbiit\Router\Exceptions\{
    RouteNotFoundException,
    MethodNotAllowedException,
    MiddlewareException
};

try {
    echo $router->dispatch($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
} catch (RouteNotFoundException $e) {
    // Handle 404 Not Found
    http_response_code(404);
    echo "Custom 404: The requested resource does not exist.";
} catch (MethodNotAllowedException $e) {
    // Handle 405 Method Not Allowed (e.g., calling POST on a GET route)
    http_response_code(405);
    echo "Custom 405: Method not allowed for this route.";
} catch (MiddlewareException $e) {
    // Handle Security or Pipeline failures
    http_response_code(403);
    error_log("Security Alert: " . $e->getMessage());
    echo "Access Denied: Security policy violation.";
} catch (\Throwable $e) {
    // Catch-all for internal server errors
    http_response_code(500);
    echo "Internal Server Error: " . $e->getMessage();
}
```

💡 Pro Tips
----------

[](#-pro-tips)

### 1. Always implement the Interface

[](#1-always-implement-the-interface)

Ensure your middlewares implement `Orbiit\Router\Contracts\MiddlewareInterface`. If they don't, the `Pipeline` will throw a `MiddlewareException`.

### 2. Dependency Injection

[](#2-dependency-injection)

The `$next` parameter in your middleware is a `callable`. To continue the request flow, you **must** return `$next($request)`.

### 3. Namespace Auto-discovery

[](#3-namespace-auto-discovery)

When using `loadController`, ensure the namespace matches your `composer.json` PSR-4 configuration.

Testing &amp; Quality (Testes e Qualidade)
------------------------------------------

[](#testing--quality-testes-e-qualidade)

• **Pest PHP:** 100% automated test coverage. • **PHPStan:** Level 8 static analysis for maximum safety.

Credits (Créditos)
------------------

[](#credits-créditos)

- [icordeiro](https://github.com/icordeiro) (Developer)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/icordeiro/orbiit-router/LICENSE) for more information.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance89

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

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

Every ~0 days

Total

6

Last Release

56d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/48436136?v=4)[Israel Cordeiro](/maintainers/icordeiro)[@icordeiro](https://github.com/icordeiro)

---

Top Contributors

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

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k104.3M822](/packages/laravel-socialite)[laravel/dusk

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

1.9k38.6M289](/packages/laravel-dusk)[pinguo/php-msf

Pinguo Micro Service Framework For PHP

1.7k4.2k](/packages/pinguo-php-msf)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)

PHPackages © 2026

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