PHPackages                             mugomes/miphantroute - 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. mugomes/miphantroute

ActiveLibrary[Framework](/categories/framework)

mugomes/miphantroute
====================

Biblioteca para trabalhar com rotas de uma forma mais fácil.

3.0.0(4mo ago)115MITPHP

Since Oct 28Pushed 4mo agoCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (0)

MiPhantRoute
============

[](#miphantroute)

**MiPhantRoute** é uma biblioteca **leve, minimalista e funcional em PHP** para **roteamento baseado em URL com suporte nativo a Expressões Regulares (Regex)**.

Ela foi criada para quem deseja **controle total**, **zero dependências** e **nenhuma abstração excessiva**, sendo ideal para todo tipo de projeto.

---

✨ Características
-----------------

[](#-características)

- Roteamento por URL com **Regex**
- Captura de parâmetros diretamente via regex
- Paradigma **funcional** (callbacks)
- Suporte a **PHP 8.4+**
- Compatível com servidor embutido (`php -S`)
- Extração de partes da URL
- Tratamento simples de **404**
- Zero dependências
- Código pequeno, legível e previsível

---

📦 Instalação
------------

[](#-instalação)

### Via Composer

[](#via-composer)

```
composer require mugomes/miphantroute
```

### Manual

[](#manual)

Copie o arquivo `MiPhantRoute.php` para seu projeto e faça a inclusão via autoloader ou `require`.

---

🚀 Uso básico
------------

[](#-uso-básico)

```
use MiPhantRoute\MiPhantRoute;

$route = new MiPhantRoute();

$route->getPart('/', function () {
    echo 'Página inicial';
});

$route->getPart('/contato', function () {
    echo 'Página de contato';
});

$route->getError(function () {
    http_response_code(404);
    echo '404 - Página não encontrada';
});
```

---

🌐 Funcionamento da URL
----------------------

[](#-funcionamento-da-url)

Para uma URL como:

```
/blog/post/123

```

A biblioteca gera internamente:

```
[
  '/blog/post/123',
  ['blog', 'post', '123']
]
```

---

🧠 Roteamento com Regex
----------------------

[](#-roteamento-com-regex)

O método `getPart()` aceita **expressões regulares completas**, permitindo capturar parâmetros da URL automaticamente.

### Exemplo simples

[](#exemplo-simples)

```
$route->getPart('/blog', function () {
    echo 'Página do blog';
});
```

---

### 📌 Captura de parâmetros

[](#-captura-de-parâmetros)

```
$route->getPart('/blog/post/([0-9]+)', function ($id) {
    echo "Post ID: {$id}";
});
```

URL acessada:

```
/blog/post/42

```

Resultado:

```
Post ID: 42

```

---

### 📌 Múltiplos parâmetros

[](#-múltiplos-parâmetros)

```
$route->getPart('/user/([a-z]+)/([0-9]+)', function ($username, $id) {
    echo "Usuário: {$username} | ID: {$id}";
});
```

URL:

```
/user/joao/10

```

---

📖 Métodos auxiliares
--------------------

[](#-métodos-auxiliares)

### `getArrayURLs(): array`

[](#getarrayurls-array)

```
$route->getArrayURLs();
// ['blog', 'post', '123']
```

---

### `getFullURL(): string`

[](#getfullurl-string)

```
$route->getFullURL();
// blog/post/123
```

---

### `getURL(int $index): string`

[](#geturlint-index-string)

```
$route->getURL(0); // blog
$route->getURL(1); // post
$route->getURL(2); // 123
```

---

### `getFirstURL(): string`

[](#getfirsturl-string)

```
$route->getFirstURL(); // blog
```

---

### `getPenultimateURL(): string`

[](#getpenultimateurl-string)

```
$route->getPenultimateURL(); // post
```

---

### `getLastURL(): string`

[](#getlasturl-string)

```
$route->getLastURL(); // 123
```

---

❌ Tratamento de erro 404
------------------------

[](#-tratamento-de-erro-404)

Se nenhuma rota corresponder, o callback definido em `getError()` será executado:

```
$route->getError(function () {
    http_response_code(404);
    echo 'Página não encontrada';
});
```

---

👤 Autor
-------

[](#-autor)

**Murilo Gomes Julio**

🔗

📺

---

📜 License
---------

[](#-license)

Copyright (c) 2025-2026 Murilo Gomes Julio

Licensed under the [MIT](https://github.com/mugomes/miphantroute/blob/main/LICENSE).

All contributions to the MiPhantRoute are subject to this license.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance76

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

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

Every ~36 days

Total

3

Last Release

128d ago

Major Versions

1.0.0 → 2.0.02025-11-17

2.0.0 → 3.0.02026-01-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/e782d9d31b820ca2583dce523269edf91ef2db0d5c48af08384fad35324643cd?d=identicon)[mugomesoficial](/maintainers/mugomesoficial)

---

Top Contributors

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

---

Tags

libraryphprouterouter

### Embed Badge

![Health badge](/badges/mugomes-miphantroute/health.svg)

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

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[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.7M259](/packages/laravel-dusk)[laravel/prompts

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

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

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

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

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