PHPackages                             louiss0/slim-route-registry - 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. louiss0/slim-route-registry

ActiveLibrary[Framework](/categories/framework)

louiss0/slim-route-registry
===========================

This package allows you to register routes and create resource controllers using attributes php

1.4.3(4y ago)015MITPHPPHP ^8.0

Since Aug 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/louiss0/slim-route-registry)[ Packagist](https://packagist.org/packages/louiss0/slim-route-registry)[ Docs](https://github.com/louiss0/slim-route-registry)[ RSS](/packages/louiss0-slim-route-registry/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (0)

   aliases    slim-route-registry-library

     tags    slim

 route-registry

     note type Main  Slim Route Registry
===================

[](#slim-route-registry)

Usage
-----

[](#usage)

The slim route registry library is a library that uses controllers and the metadata that comes from them to automatically create route groups and setup middleware. The controller is used as the model for how routes are created and what methods they use. This library is created for [slim](https://www.slimframework.com) php only.

### Installation

[](#installation)

```
composer require louiss0/slim-route-registry
```

### Setup

[](#setup)

To setup the library you have to first create the slim app and pass it into the setup method.

```
use Slim\Factory\AppFactory;
use Louiss0\SlimRouteRegistry\RouteRegstry

$app = AppFactory::create();

RouteRegistry::setup($app);
```

Doing this will setup all of the systems necessary to create controllers called **["Resource Controllers"](#resources)**

Sections
--------

[](#sections)

- [Resources](#resources)
    - [Manual Resources](#manual-resources)
    - [Automatic Resources](#automatic-resources)
- [Group Scoping](#group-scoping)
- [Middleware](#middleware)
    - [Resource Middleware](#resource-middleware)
    - [Method Middleware](#method-middleware)
    - [Group Middleware](#group-middleware)

[Resources](#sections)
----------------------

[](#resources)

A Resource Controller is a controller that either has a route method attribute attached to a method or uses a Automatic Registration Method. It's a controller with the necessary information needed for the Resource method to work. To create a resource you create a class then attach a Route Method Attribute to one of its methods.

- To register a resource you use the Route Registry resource method.

```
RouteRegistry::resource(string $path, string $class_name);
```

- To register multiple resources use the resources method

```
RouteRegistry::resource(array $resource_options);
```

### [Manual Resources](#sections)

[](#manual-resources)

A Manual Resource is a controller that is created by attaching route method attributes as to its methods. The route attributes will tell the `RouteMethodAttribute` is the main attribute all other attributes stem inherit from this attribute with a predefined http request method.

A route method attribute is an attribute that takes three parameters.

- path - The path of the route relative to the [group scope](#group-scoping)
- name - The name of the route that will be created
- method - The http request **in lowercase** the method will respond to

> Note you don't need to use the Route Method Attribute directly you can use Attributes that are inherited from them instead.

```
// will tell the resource method to register a http get request
#[Get(name, path)]
function fetchTheCars(){}

// will tell the resource method to register a http post request
#[Post(name, path)]
function loginAUser(){}

// will tell the resource method to register a http patch request
#[Patch(name, path)]
function changeTheCarInfo(){}

// will tell the resource method to register a http put request
#[Put(name, path)]
function putTheArticleInTheCollectionOrCreateANewOne(){}

// will tell the resource method to register a http delete request
#[Delete(name, path)]
function deleteThisPost(){}
```

### [Automatic Resources](#sections)

[](#automatic-resources)

An Automatic Resource is a controller that uses a Automatic Registration Method.

An Automatic Registration Method is a method that has a name that will be used by the resource method to register a route based on it's name.

```
	// Will be used as a plain get request handler
	function collect() {}

	// Will be used as a  get request handler with id passed as params
	function show() {}

	// Will be used as a plain post request handler
	function store() {}

	// Will be used as a  put request handler with id passed as params
	function upsert() {}

	// Will be used as a  patch request handler with id passed as params
	function update() {}

	// Will be used as a  delete request handler with id passed as params
	function destroy() {}
```

> Note: If you add a route method attribute to one of these methods you'll get an error

> Note: The id parameter must be an int

[Group Scoping](#sections)
--------------------------

[](#group-scoping)

In most apps you want to have the power to wrap resources under a group that will be be used to either call middleware before any of their methods are called or controlling the path the user must use to access a resource. To do this you use the group method.

```
RouteRegistry::group(string $path, Closure $closure);
```

- The path is the pattern that will be used in the group method
- The closure will be the function that will be called in the closure of the group method. When you use the resource method in the closure passed the resource path will be appended to the group path as usual

[Middleware](#sections)
-----------------------

[](#middleware)

You can use middleware in your app by using Use Middleware Attributes on methods and controllers and controller methods. You can tell the resource method to create the same middleware to be called before a request handler is called or before multiple request handlers are called.

```
#[UseMiddleware([TestMiddleware::class])]
class Controller {}

class Controller {

	#[UseMiddleware([TestMiddleware::class])]
	function getOrdersByName(){}

}
```

### [Resource Middleware](#sections)

[](#resource-middleware)

To apply middleware to a route group created from the resource method you use the Use Middleware Attribute on a controller.

```
	// takes a string of middleware
	#[UseMiddleware(array $middleware)]
	class PostController {}
```

### [Method Middleware](#sections)

[](#method-middleware)

When it comes to putting middleware in a route you must use a class that implements the Middleware interface as a attribute or the following attributes on a controller:

```
#[UseMiddlewareOn(array $method_names, array $middleware)]
	class AuthController {}
```

- The method names are the names of the handlers for the routes the middleware will be added to. The middleware will only go to those routes.

```
#[UseMiddlewareExceptFor(array $method_names, array $middleware)]
	class PostController {}
```

- The method names are the names of the handlers for the routes the middleware will not be added to. The middleware go to every route but those routes.

> Note: The middleware will be applied in the following order.
>
> 1. `UseMiddlewareOn`
> 2. `UseMiddlewareExceptFor`

> Note: The `UseMiddlewareOn` and Use `UseMiddlewareExceptFor` attributes are repeatable

```
#[
	UseMiddlewareOn(
		["collect", "destroy"],
		[]
	),
	UseMiddlewareOn(
		["update", "store"],
	)
]
class Controller {}
```

```
#[
UseMiddlewareOn(["collect", "store"],[Test4Middleware::class])
UseMiddlewareExceptOn(["collect", "upsert"],[Test3Middleware::class])

]
class Controller {}
```

### [Group Middleware](#sections)

[](#group-middleware)

To add middleware to a group use the created by the `RouteRegistry::group()` method use

```
RouteRegistry::groupMiddleware(MiddlewareInterface...$middleware);
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~14 days

Total

10

Last Release

1655d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b308f4c5aaef9cdac1157a36d7baa82ffed274effc20abb28f17a09c21b8580?d=identicon)[louiss0](/maintainers/louiss0)

---

Top Contributors

[![louiss0](https://avatars.githubusercontent.com/u/29028601?v=4)](https://github.com/louiss0 "louiss0 (69 commits)")

---

Tags

slimrouting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/louiss0-slim-route-registry/health.svg)

```
[![Health](https://phpackages.com/badges/louiss0-slim-route-registry/health.svg)](https://phpackages.com/packages/louiss0-slim-route-registry)
```

###  Alternatives

[duxweb/dux-lite

The lightweight framework based on slim php

161.0k9](/packages/duxweb-dux-lite)

PHPackages © 2026

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