PHPackages                             nicollassilva/minasrouter - 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. nicollassilva/minasrouter

ActiveLibrary

nicollassilva/minasrouter
=========================

MinasRouter is simple, fast and extremely readable for routes.

V1.0.5(4y ago)141142[1 issues](https://github.com/nicollassilva/minasrouter/issues)MITPHPPHP &gt;=7.2

Since Jun 9Pushed 4y ago2 watchersCompare

[ Source](https://github.com/nicollassilva/minasrouter)[ Packagist](https://packagist.org/packages/nicollassilva/minasrouter)[ RSS](/packages/nicollassilva-minasrouter/feed)WikiDiscussions master Synced 2d ago

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

Router @MinasRouter
===================

[](#router-minasrouter)

[![a](https://user-images.githubusercontent.com/10711363/121407187-6b904a00-c935-11eb-84a0-5fae3d7a9deb.PNG)](https://user-images.githubusercontent.com/10711363/121407187-6b904a00-c935-11eb-84a0-5fae3d7a9deb.PNG)

[![Maintainer](https://camo.githubusercontent.com/70c19da2a3ddae13529df7fb1d4998cb4aecaa61c7122b98b77fca7e1318a57d/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d406e69636f6c6c617373696c76612d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/nicollassilva)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3b3aeb01c81f07c5461c13afdb1f44c830417e785b7b5429e68418537596da3d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e69636f6c6c617373696c76612f6d696e6173726f757465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nicollassilva/minasrouter/?branch=master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/1b53b8dd03579e5a4aeccc9d729f98822abbe31aacc6543f709c5616f3895e7a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6e69636f6c6c617373696c76612f6d696e6173726f757465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/nicollassilva/minasrouter/releases)[![Build Status](https://camo.githubusercontent.com/b0581d99465b08ee3056179707ffaf75366b08327ebf9964bf20ee5891215af9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e69636f6c6c617373696c76612f6d696e6173726f757465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nicollassilva/minasrouter/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/641e53bbd0b3381a5ddd86c213539a3b29890c6d3ee62892c07ec884b7ee7f0d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e69636f6c6c617373696c76612f6d696e6173726f757465722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

#### MinasRouter is simple, fast and extremely readable for routes. Create and manage your routes in just a few steps.

[](#minasrouter-is-simple-fast-and-extremely-readable-for-routes-create-and-manage-your-routes-in-just-a-few-steps)

> Simples, rápido e MUITO funcional. **MinasRouter** é um componente de rotas PHP para projetos MVC! Foi feito para abstrair os verbos RESTfull `(GET, POST, PUT, PATCH, DELETE)` e renderizar de forma simples e fácil no controller da aplicação.

> `MinasRouter` trabalha e processa todas as informações de forma isolada, facilitando o processo para o desenvolvedor e acelerando o desenvolvimento/andamento do projeto.

Simple, fast and VERY functional. **MinasRouter** is a PHP routes component for MVC projects! It is designed to abstract the RESTfull (GET, POST, PUT, PATCH, DELETE) verbs and render them simply and easily in the application controller.

**MinasRouter** works and processes all information in isolation, facilitating the process for the developer and accelerating the development/progress of the project.

Highlights @MinasRouter
=======================

[](#highlights-minasrouter)

- In a few minutes you can create routes for your application or api `(Yes, it really is a few minutes)`
- Fast and Easy middleware system
- Respect the RESTfull verbs and has great functions to deal with them
- Route customization, regex in dynamic parameters and optional parameters
- Spoofing for verbalization and data control (FormSpoofing)
- Carries dynamic parameters to controller arguments
- Easy routing groups and fast create
- It has a **Request Class** to control and work with route data

> With **two lines** you start using routes!

Application example
===================

[](#application-example)

Maybe you are a person who learns by watching, you can access the [example](https://github.com/nicollassilva/minasrouter/tree/master/example) folder, which contains an folders architecture example of how we use MinasRouter.

Tests
=====

[](#tests)

> You can check all tests done [here](https://github.com/nicollassilva/minasrouter/tree/master/tests). Enjoy!

Installation
============

[](#installation)

MinasRouter is available via `Composer require`:

```
"require" {
    "nicollassilva/minasrouter": "^1.0"
}
```

or run in **terminal**:

```
composer require nicollassilva/minasrouter
```

Documentation
=============

[](#documentation)

### 1. Configuration

[](#1-configuration)

- [Redirect to Public Folder](https://github.com/nicollassilva/minasrouter#redirect-to-public-folder)

- **Public Folder Configuration**

- [Apache](https://github.com/nicollassilva/minasrouter#apache)
- [Nginx](https://github.com/nicollassilva/minasrouter#apache)

### 2. Routes

[](#2-routes)

- [My first Route](https://github.com/nicollassilva/minasrouter#the-first-route)
- [RESTfull Verbs](https://github.com/nicollassilva/minasrouter#restfull-verbs)

- **Customization**

- [Named Routes](https://github.com/nicollassilva/minasrouter#named-routes)
- [Dynamic Parameters (Required and Optional)](https://github.com/nicollassilva/minasrouter#dynamic-parameters-required-and-optional)
- [Validating a Dynamic Parameter](https://github.com/nicollassilva/minasrouter#validating-a-dynamic-parameter)

- **Middlewares**

- [Set Global Middlewares](https://github.com/nicollassilva/minasrouter#set-global-middlewares)
- [Attach in a route](https://github.com/nicollassilva/minasrouter#attach-in-a-route)
- [Delete a middleware](https://github.com/nicollassilva/minasrouter#delete-a-middleware)

- **Route Groups**

- [All Methods](https://github.com/nicollassilva/minasrouter#route-groups)
- [Named Group](https://github.com/nicollassilva/minasrouter#named-group)
- [Prefixed Group](https://github.com/nicollassilva/minasrouter#prefixed-group)
- [Default Namespace Group](https://github.com/nicollassilva/minasrouter#default-namespace-group)
- [Default Middleware Group](https://github.com/nicollassilva/minasrouter#default-middleware-group)
- [Nested Group Methods](https://github.com/nicollassilva/minasrouter#nested-group-methods)

- **Others**

- [Route Redirect](https://github.com/nicollassilva/minasrouter#route-redirect)
- [Route with Individual Middleware in Group](https://github.com/nicollassilva/minasrouter#route-with-individual-middleware-in-group)
- [Route with Different Name in Group](https://github.com/nicollassilva/minasrouter#route-with-different-name-in-group)
- [Fallback Routes](https://github.com/nicollassilva/minasrouter#fallback-routes)

### 3. Request Route

[](#3-request-route)

- [Introduction](https://github.com/nicollassilva/minasrouter#request-route)

- **Methods**

- [Request Path](https://github.com/nicollassilva/minasrouter#retrieving-the-request-path)
- [Request URL](https://github.com/nicollassilva/minasrouter#retrieving-the-request-url)
- [Request Headers](https://github.com/nicollassilva/minasrouter#request-headers)
- [Request IP Address](https://github.com/nicollassilva/minasrouter#request-ip-address)
- [Retrieving Data](https://github.com/nicollassilva/minasrouter#retrieving-data)
- [Request Method](https://github.com/nicollassilva/minasrouter#retrieving-the-request-method)

Introduction
============

[](#introduction)

> Para começar a usar o MinasRouter, todo o gerenciamento da navegação deverá ser redirecionado para o arquivo padrão de rotas do seu sistema, que fará todo o processo de tratamento das rotas e retornará o que foi por padrão configurado. Configure conforme os exemplos abaixo e de acordo com seu servidor.

To start using MinasRouter, all navigation management must be redirected to your system's default route file, which will do the entire route handling process and return what was configured by default. Configure according to the examples below and according to your server.

Redirect to Public Folder
-------------------------

[](#redirect-to-public-folder)

```
RewriteEngine on
Options All -Indexes

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} (www\.)?localhost
RewriteRule (.*) https://%{HTTP_HOST} [L,R=301]

RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
```

### apache

[](#apache)

```
RewriteEngine On
#Options All -Indexes

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

### Do not use the settings below if you are using developing in a local environment, use only in production.

## WWW Redirect
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## HTTPS Redirect
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```

### nginx

[](#nginx)

```
location / {
  if ($script_filename !~ "-f"){
    rewrite ^(.*)$ /index.php?route=/$1 break;
  }
}
```

The first Route
===============

[](#the-first-route)

To start the components:

```
