PHPackages                             nicc0/slim-annotation-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. [HTTP &amp; Networking](/categories/http)
4. /
5. nicc0/slim-annotation-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nicc0/slim-annotation-router
============================

Slim Annotation Router for Slim 4

0.5.1(5y ago)61782[1 issues](https://github.com/Nicc0/Slim-Annotation-Router/issues)MITPHPPHP ^7.1 || ~8.0

Since Jul 9Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Nicc0/Slim-Annotation-Router)[ Packagist](https://packagist.org/packages/nicc0/slim-annotation-router)[ Docs](https://github.com/nicc0/slim-annotation-router)[ RSS](/packages/nicc0-slim-annotation-router/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (5)Versions (13)Used By (0)

Slim-Annotation-Router
======================

[](#slim-annotation-router)

 [ ![Latest Version on Packagist](https://camo.githubusercontent.com/c5a0dc5209dd789183e2906cc1b336f6e3e30553269ec2f6262bfda035ff5d94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4e696363302f736c696d2d616e6e6f746174696f6e2d726f757465722e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/nicc0/slim-annotation-router) [ ![Latest PHP Version](https://camo.githubusercontent.com/0bd6d77c9dbd5a9bcbdf81e4427a0dbe28e763d61e2764af2a7898da88f0593d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e696363302f736c696d2d616e6e6f746174696f6e2d726f757465722e7376673f7374796c653d666c61742d737175617265) ](#) [ ![License](https://camo.githubusercontent.com/bafa0420d14738c5e067e291c46375c16e7ab7110645365b01e69efa7229aec6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4e696363302f536c696d2d416e6e6f746174696f6e2d526f757465722e7376673f7374796c653d666c61742d737175617265) ](https://github.com/Nicc0/Slim-Annotation-Router/blob/master/LICENSE) [ ![Build Status](https://camo.githubusercontent.com/78b8354f2479e31211f3bab085a095abd0d5626a05737f8c569ccd0d71e2f0b1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4e696363302f536c696d2d416e6e6f746174696f6e2d526f757465722e7376673f7374796c653d666c61742d737175617265) ](https://travis-ci.org/Nicc0/slim-annotation-router) [ ![Coverages](https://camo.githubusercontent.com/dfde10eb88293d6693c9ac5758e08db4b898cddfcf555f32a5be68f991f0d69a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e696363302f736c696d2d616e6e6f746174696f6e2d726f757465722e7376673f7374796c653d666c61742d737175617265) ](https://codecov.io/gh/Nicc0/slim-annotation-router)

Annotation Router for [Slim 4.x](https://github.com/slimphp/Slim/tree/4.x)

Installation
------------

[](#installation)

It's recommended using [Composer](https://getcomposer.org/) to install Slim Annotation Router.

```
$ composer require "nicc0/slim-annotation-router"
```

This will install Slim Annotation Router and all required dependencies. Remember Slim 4.x requires PHP 7.1 or newer.

Usage
-----

[](#usage)

```
$factory = new DecoratedResponseFactory( new ResponseFactory(), new StreamFactory() );
$resolver = new CallableResolver();

$controllerPath = './app/controllers/';

$collector = new AnnotationRouteCollector( $factory, $resolver, $container );
$collector->setDefaultControllersPath( $controllersPath );
$collector->collectRoutes();

$app = new App( $factory, $container, $resolver, $collector );
```

Creating Routes by Annotation
-----------------------------

[](#creating-routes-by-annotation)

```
/**
 * Class ExampleController
 *
 * @RoutePrefix("/example")
 */
class ExampleController
{
    /**
     * @Route("/hello", methods={"GET"}, name="example.hello")
     *
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function hello(): ResponseInterface
    {
        $response = new Response();
        $response->getBody()->write('Hello world!');

        return $response;
    }
}
```

By opening the url http://your\_site\_url/example/hello, you should see "Hello world!".

Adding Middlewares to contoller by Annotation
---------------------------------------------

[](#adding-middlewares-to-contoller-by-annotation)

To add Middleware to Controller or Action use `@Middleware("")` annotation, which pass the name of Middleware. It is important to know that the name we pass must be defined in the Container. Name passes as the third parameter in the `AnnotationRouteCollector` constructor. It is also important that the added Middleware must implements of `MiddlewareInterface` otherwise Middleware will not be added to the Route.

There is also possibility to add more than one Middleware to Controller or Action.

For example, we have to add AuthMiddleware to controller. Firstly we have to define AuthMiddleware in Container.

```
$container->set('authMiddleware', function() use ($container) {
    return new AuthContainer(container);
})
```

If Middleware exists in our Container, now we can use middleware annotation by adding `@Middleware("authMiddleware")` to controller.

```
/**
 * @RoutePrefix("/example")
 * @Middleware("authMiddleware")
 */
class ExampleController
{
    /**
     * @Route("/hello", methods={"GET"}, name="example.hello")
     */
    public function hello(): ResponseInterface
    {
        ...
    }
}
```

Tests
-----

[](#tests)

To execute the test suite, you'll need to install all development dependencies.

```
git clone https://github.com/Nicc0/Slim-Annotation-Router
composer install
composer test
```

License
-------

[](#license)

The Slim Annotation Router is licensed under the MIT license. See [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

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

Recently: every ~105 days

Total

12

Last Release

1882d ago

PHP version history (2 changes)0.3.1PHP ^7.1

0.5.1PHP ^7.1 || ~8.0

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

annotationbridgelibrarypsr7routerslimrestrouterpsr7libraryslimBridgeannotation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nicc0-slim-annotation-router/health.svg)

```
[![Health](https://phpackages.com/badges/nicc0-slim-annotation-router/health.svg)](https://phpackages.com/packages/nicc0-slim-annotation-router)
```

PHPackages © 2026

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