PHPackages                             matinkiani/simple-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. matinkiani/simple-router

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

matinkiani/simple-router
========================

A Simple PHP router

v0.1.0(1y ago)01MITPHPPHP &gt;=8.1CI passing

Since Jan 26Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Simple PHP Router
=================

[](#simple-php-router)

[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/67db1cf7491c08e5b64133afb24000e59b5faf706e95a49a27c9d665c96962eb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d76302e312e302d626c75652e737667)](https://github.com/yourusername/simple-router/releases)

A lightweight and simple PHP router inspired by Laravel's routing system. This is a personal project created for learning purposes and is not intended for production use yet.

🚀 Features
----------

[](#-features)

- Simple and intuitive API
- Support for GET, POST, PUT, PATCH, and DELETE methods
- Route parameters with named capture groups
- Route grouping with prefixes
- Middleware support (global and group-specific)
- Named routes
- Route parameter constraints
- PSR-4 compliant

📦 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require matinkiani/simple-router
```

🔧 Usage
-------

[](#-usage)

### Basic Routing

[](#basic-routing)

```
use MatinKiani\SimpleRouter\Router;

$router = new Router();

// Define routes
$router->get('/', function() {
    return 'Hello World!';
});

$router->get('/users/{id}', function($id) {
    return "User {$id}";
})->name('user.show');

// Handle the request
$response = $router->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
echo $response;
```

### Route Groups

[](#route-groups)

```
$router->group([
    'prefix' => '/admin',
    'middleware' => function($next) {
        // Check if user is admin
        if (!isAdmin()) {
            return 'Unauthorized';
        }
        return $next();
    }
], function() use ($router) {
    $router->get('/dashboard', function() {
        return 'Admin Dashboard';
    });

    $router->get('/users', function() {
        return 'Admin Users List';
    });
});
```

### Named Routes

[](#named-routes)

- Note that dynamic parameters are not supported in named routes yet.

```
$router->get('/posts', function() {
    return "Post";
})->name('post.show');

// Generate URL
$url = $router->route('post.show'); // Returns: /posts
```

### Middleware

[](#middleware)

```
// Global middleware
$router->addGlobalMiddleware(function($next) {
    // Do something before
    $response = $next();
    // Do something after
    return $response;
});

// Route specific middleware
$router->get('/protected', function() {
    return 'Protected Content';
})->middleware(function($next) {
    if (!isAuthenticated()) {
        return 'Please login';
    }
    return $next();
});
```

🛣️ Roadmap
----------

[](#️-roadmap)

- Add support for dynamic parameters in named routes
- Add support for controllers
- Implement route caching
- Add regex pattern constraints for parameters
- Add optional parameters
- Add support for domain routing
- Add support for rate limiting
- Implement proper request/response objects
- Add proper error handling and custom error pages
- Add proper documentation
- Add support for dependency injection

🤝 Contributing
--------------

[](#-contributing)

This is a personal project, but contributions are welcome! Feel free to:

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

📝 License
---------

[](#-license)

This project is open-sourced software licensed under the MIT license.

⚠️ Disclaimer
-------------

[](#️-disclaimer)

This router is inspired by Laravel's routing system but was built from scratch without checking Laravel's source code. It's currently in early development (v0.1.0) and is primarily a learning project. While you're free to use it, it's recommended to use established routing solutions for production applications.

🙏 Acknowledgments
-----------------

[](#-acknowledgments)

- Inspired by Laravel's elegant routing system
- Built with love for the PHP community

📬 Contact
---------

[](#-contact)

Made with ❤️ by Matin Kiani -

---

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance42

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

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

469d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

phprouterphppackagerouter

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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