PHPackages                             carlosartur/slim-auto-routing-controller - 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. [API Development](/categories/api)
4. /
5. carlosartur/slim-auto-routing-controller

ActiveLibrary[API Development](/categories/api)

carlosartur/slim-auto-routing-controller
========================================

Auto generate routes from class methods on slim framework.

0.0.3(3y ago)07MITPHPPHP ^7.4 || ~8.0.0 || ~8.1.0

Since Oct 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/carlosartur/SlimAutoRoutingController)[ Packagist](https://packagist.org/packages/carlosartur/slim-auto-routing-controller)[ RSS](/packages/carlosartur-slim-auto-routing-controller/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

SlimAutoRoutingController
=========================

[](#slimautoroutingcontroller)

This library adds a abstract controller to auto generate routes for a slim framework project.

How to use
----------

[](#how-to-use)

### Install

[](#install)

```
composer require carlosartur/slim-auto-routing-controller

```

### Supported HTTP Methods

[](#supported-http-methods)

- GET
- POST
- PUT
- DELETE
- OPTIONS
- PATCH

### Usage example

[](#usage-example)

#### How it works

[](#how-it-works)

- To generate *path*
    - If the controller has "ROUTE\_FIXED" constant defined:
        - Use value of "ROUTE\_FIXED" constant as path.
    - Else:
        - Get the controller's name.
        - Remove "Controller" word of it.
        - Slugify the remaining string.
        - Prefix it with value of "ROUTE\_PREFIX" constant (optional).
- To generate a route:
    - Searches on controller the **public** methods which have the word "Action" on it's name, in any part of name.
        - To change the "Action" word to anything else, add a "METHOD\_ROUTE\_SUFFIX" constant on controller, with another word.
    - To generate a "GET" action, the method must have the "GET" word inside it's name.
    - To generate a "POST" action, the method must have the "POST" word inside it's name.
    - To generate a "PUT" action, the method must have the "PUT" word inside it's name.
    - To generate a "DELETE" action, the method must have the "DELETE" word inside it's name.
    - To generate a "OPTIONS" action, the method must have the "OPTIONS" word inside it's name.
    - To generate a "PATCH" action, the method must have the "PATCH" word inside it's name.
    - If method's name is more than &lt;verb&gt;&lt;suffix&gt;:
        - Remove http verb and suffix from name;
        - Slugify the remaining string
        - Add result of slug to ***path***
- Parameters and Validation parameter's regex:
    - To add parameter, just add it on method, after "Request" and "Response" parameters.
    - To validate it, 2 ways are possible
        - By type:
            - Add a "TYPES\_REGEX" constant on your controller, or use the library default, wich validates float and int only.
        - By name:
            - Add a "PARAMETER\_VALIDATION\_REGEX" constant on your controller, or use the library default, wich validates a parameter named "id" as a integer value.

#### Controller

[](#controller)

```
