PHPackages                             gaetanroger/slim-routes-loader - 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. gaetanroger/slim-routes-loader

ActiveLibrary[API Development](/categories/api)

gaetanroger/slim-routes-loader
==============================

Register your Slim routes using a simple config file.

0.2(8y ago)019MITPHP

Since Nov 25Pushed 8y agoCompare

[ Source](https://github.com/GaetanRoger/slim-routes-loader)[ Packagist](https://packagist.org/packages/gaetanroger/slim-routes-loader)[ RSS](/packages/gaetanroger-slim-routes-loader/feed)WikiDiscussions master Synced yesterday

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

Slim routes loader
==================

[](#slim-routes-loader)

[![Build Status](https://camo.githubusercontent.com/91a8f9791bbaf246ad178b2a6ab2b5fa788c2324ae74d82cc54b3d0b626567e0/68747470733a2f2f7472617669732d63692e6f72672f47616574616e526f6765722f736c696d2d726f757465732d6c6f616465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/GaetanRoger/slim-routes-loader)

When using [Slim PHP Framework](https://www.slimframework.com/), you need to register your routes. This library allows you to do so via a simple config file.

How to install
--------------

[](#how-to-install)

Using composer is the easiest way.

```
composer require gaetanroger/slim-routes-loader

```

You can always get the sources from this repo and install it manually in your project.

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

[](#how-to-use)

*For more info about the syntax to follow, see [Syntax and rules](#syntax-and-rules).*

### Regular PHP array format

[](#regular-php-array-format)

Write your routes using a regular PHP associative array, then use the `Loader` class to import it.

```
$routes = [
    'pattern' => '',
    'routes'  => [
        [
            'pattern'  => '/',
            'method'   => 'GET',
            'callable' => 'myCallable',
            'name'     => 'optianalName',
        ],
    ],
];
$slim = new \Slim\App();

$loader = new Gaetanroger\SlimRoutesLoader\Loader($routes);
$loader->load($slim); // or $loader($slim)
```

If you want to store your routes in another file, simply include them using a regular PHP `require`.

```
$routes = require __DIR__ '/myRoutes.php';
$slim = new \Slim\App();

$loader = new \Gaetanroger\SlimRoutesLoader\Loader($routes);
$loader($slim); // or $loader->load($slim)
```

### Json format

[](#json-format)

If you prefer to write your routes as Json, simply use the `JsonLoader`.

```
{
    "pattern": "",
    "routes": [
        {
            "pattern": "/",
            "method": "GET",
            "callable": "testCallable",
            "name": "testName"
        }
    ]
}
```

```
$slim = new \Slim\App();

$loader = new \Gaetanroger\SlimRoutesLoader\JsonLoader($json);
$loader($slim); // or $loader->load($slim)
```

The `$json` variable can contain a json string or the path to a json file containing the routes.

### Yaml format

[](#yaml-format)

If you prefer to write your routes as Yaml, simply use the `YmlLoader`.

```
pattern:
routes:
  - pattern: /
    method: GET
    callable: testCallable
    name: testName
```

```
$slim = new \Slim\App();

$loader = new \Gaetanroger\SlimRoutesLoader\YmlLoader($yml);
$loader($slim); // or $loader->load($slim)
```

The `$yml` variable can contain a Yaml string or the path to a Yaml file containing

### Syntax and rules

[](#syntax-and-rules)

No matter what format you choose to use, the loaders require a certain syntax.

Please see the [Slim documentation](https://www.slimframework.com/docs/objects/router.html)to get more info about specific points.

#### Route syntax

[](#route-syntax)

- `pattern`: the route pattern
- `method`: the HTTP method the route is waiting for (GET, POST, etc.)
- `callable`: the function/method/invokable to be called when the route is reached
- `name`: (optional) the name of the route

#### Group syntax

[](#group-syntax)

- `pattern`: the group pattern
- `routes`: an array containing other groups or routes

#### General rules

[](#general-rules)

- The top element must be a group (usually with an empty pattern unless you want to prefix all your routes)
- A pattern can be left empty.

Examples
--------

[](#examples)

### PHP array syntax

[](#php-array-syntax)

```
$routes = [
    'pattern' => '',
    'routes'  => [
        [
            'pattern'  => '/one',
            'method'   => 'GET',
            'callable' => 'testCallable1',
            'name'     => 'testName1',
        ],
        [
            'pattern'  => '/two',
            'method'   => 'POST',
            'callable' => 'testCallable2',
            'name'     => 'testName2',
        ],
        [
            'pattern' => '/group',
            'routes'  => [
                [
                    'pattern'  => '/one',
                    'method'   => 'GET',
                    'callable' => 'testCallable1',
                    'name'     => 'testName1',
                ],
                [
                    'pattern'  => '/two',
                    'method'   => 'POST',
                    'callable' => 'testCallable2',
                    'name'     => 'testName2',
                ],
            ],
        ],
    ],
];
```

### Json syntax

[](#json-syntax)

```
{
    "pattern": "",
    "routes": [
        {
            "pattern": "/one",
            "method": "GET",
            "callable": "testCallable1",
            "name": "testName1"
        },
        {
            "pattern": "/two",
            "method": "POST",
            "callable": "testCallable2",
            "name": "testName2"
        },
        {
            "pattern": "/group",
            "routes": [
                {
                    "pattern": "/one",
                    "method": "GET",
                    "callable": "testCallable1",
                    "name": "testName1"
                },
                {
                    "pattern": "/two",
                    "method": "POST",
                    "callable": "testCallable2",
                    "name": "testName2"
                }
            ]
        }
    ]
}
```

### Yaml syntax

[](#yaml-syntax)

```
pattern:
routes:
  - pattern: /one
    method: GET
    callable: testCallable1
    name: testName1
  - pattern: /two
    method: POST
    callable: testCallable2
    name: testName2
  - pattern: /group
    routes:
      - pattern: /one
        method: GET
        callable: testCallable1
        name: testName1
      - pattern: /two
        method: POST
        callable: testCallable2
        name: testName2';
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

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

Total

2

Last Release

3090d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/21ac8587f9fb4b0515685cbe62cdc7eca55d2ba834361e4376aee5f803505e0c?d=identicon)[GaetanRoger](/maintainers/GaetanRoger)

---

Top Contributors

[![GaetanRoger](https://avatars.githubusercontent.com/u/24687462?v=4)](https://github.com/GaetanRoger "GaetanRoger (22 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gaetanroger-slim-routes-loader/health.svg)

```
[![Health](https://phpackages.com/badges/gaetanroger-slim-routes-loader/health.svg)](https://phpackages.com/packages/gaetanroger-slim-routes-loader)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)

PHPackages © 2026

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