PHPackages                             tarikweiss/slim-attribute-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. tarikweiss/slim-attribute-router

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

tarikweiss/slim-attribute-router
================================

A simple library for applying routing with attributes.

0.1.1(1y ago)1153MITPHPPHP ^8.1

Since Aug 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/tarikweiss/slim-attribute-router)[ Packagist](https://packagist.org/packages/tarikweiss/slim-attribute-router)[ RSS](/packages/tarikweiss-slim-attribute-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

slim-attribute-router
=====================

[](#slim-attribute-router)

This is a small library for mapping routes with an attribute.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Slim 4.0 or higher

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

[](#installation)

```
composer require tarikweiss/slim-attribute-router
```

### Installation of router

[](#installation-of-router)

```
$router = new \Tarikweiss\SlimAttributeRouter\Router(
    ['/path/to/project/src/Action'],
    new \Tarikweiss\SlimAttributeRouter\PublicMethodRouteTargetCreator('run')
);

/** @var \Slim\App $slimApp */
$router->registerRoutes($slimApp);
```

### Installation of Route attribute

[](#installation-of-route-attribute)

The GET and POST is installed on class level, the PATCH method is installed on method level.

```
#[\Tarikweiss\SlimAttributeRouter\Route(
    methods: ['GET', 'POST'],
    path: '/foo'
)]
class FooAction
{
    /**
     * Here the name given in the constructor of the PublicMethodRouteTargetCreator is used.
     */
    public function run(
        \Psr\Http\Message\ServerRequestInterface $request,
        \Psr\Http\Message\ResponseInterface      $response,
        array                                    $arguments
    ): \Psr\Http\Message\ResponseInterface {
        // Do you request handling and respond to the request.
        // This structure is given by Slim!
        // Have a look at the docs: https://www.slimframework.com/docs/v4/start/installation.html#step-4-hello-world
        return $response;
    }

    #[\Tarikweiss\SlimAttributeRouter\Route(
        methods: ['PATCH'],
        path: '/foo'
    )]
    public function anotherActionHandler(
        \Psr\Http\Message\ServerRequestInterface $request,
        \Psr\Http\Message\ResponseInterface      $response,
        array                                    $arguments
    ): \Psr\Http\Message\ResponseInterface {
        // Same structure as above, but different scope.
        return $response;
    }
}
}
```

### Custom RouteTargetCreator

[](#custom-routetargetcreator)

If you require to create a custom callable or callable string for Slim's route registration, then you may implement the `\Tarikweiss\SlimAttributeRouter\RouteTargetCreator` interface. It gives you full handling over the registration level (class or method) and the class (and method) that should be registered.

Here is a sample implementation, the RouteTargetCreator for public methods (shipped with library).

```
class PublicMethodRouteTargetCreator implements \Tarikweiss\SlimAttributeRouter\RouteTargetCreator
{
    public function __construct(
        public string $classLevelMethodName = 'run'
    )
    {
    }

    public function createRouteTarget(\Tarikweiss\SlimAttributeRouter\RouteLevel $routeLevel, string $class, ?string $method): callable|string
    {
        return match ($routeLevel) {
            \Tarikweiss\SlimAttributeRouter\RouteLevel::LEVEL_CLASS  => $class . ':' . $this->classLevelMethodName,
            \Tarikweiss\SlimAttributeRouter\RouteLevel::LEVEL_METHOD => $class . ':' . $method,
        };
    }
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

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

Total

2

Last Release

607d ago

### Community

Maintainers

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

---

Top Contributors

[![tarikweiss](https://avatars.githubusercontent.com/u/6708551?v=4)](https://github.com/tarikweiss "tarikweiss (9 commits)")

---

Tags

httpslim

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tarikweiss-slim-attribute-router/health.svg)

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

###  Alternatives

[chadicus/slim-oauth2

OAuth2 routes, middleware and utilities for use within a Slim Framework API

129365.9k3](/packages/chadicus-slim-oauth2)[palanik/corsslim

Cross-origin resource sharing (CORS) middleware for PHP Slim.

94375.3k3](/packages/palanik-corsslim)[chadicus/slim-oauth2-http

Bridge components for PSR-7 and bshaffer's OAuth2 Server http messages.

18455.2k7](/packages/chadicus-slim-oauth2-http)[maurobonfietti/slim4-api-skeleton

Useful skeleton for RESTful API development, using PHP and Slim 4.

1392.3k](/packages/maurobonfietti-slim4-api-skeleton)[mhndev/slim-file-response

Slim File Response

112.5k](/packages/mhndev-slim-file-response)

PHPackages © 2026

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