PHPackages                             giacomofurlan/slim3annotation-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. [API Development](/categories/api)
4. /
5. giacomofurlan/slim3annotation-router

ActiveLibrary[API Development](/categories/api)

giacomofurlan/slim3annotation-router
====================================

Enables to define routes via the @Route(...) annotation

v1.0.2(10y ago)1511GNU GPL v3PHPPHP &gt;=5.6.6

Since Jun 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/elegos/slim3AnnotationRouter)[ Packagist](https://packagist.org/packages/giacomofurlan/slim3annotation-router)[ Docs](https://github.com/elegos)[ RSS](/packages/giacomofurlan-slim3annotation-router/feed)WikiDiscussions master Synced 3w ago

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

Slim3 Annotation Router
-----------------------

[](#slim3-annotation-router)

**by [Giacomo Furlan](http://giacomofurlan.name "Giacomo Furlan's website")**

This library allows routes to be defined in [Slim3](https://github.com/slimphp/Slim) with annotations instead of defining them programmatically (in a similar way Symfony does).

---

This is free software under the GNU GPL v3. See the licence file for more information.

---

Supported syntax:

```
/**
* @Route("/class/route/prefix")
*/
class MyController {
    /**
    * @Route("/path/{arg}/{arg2}", name="route.name" methods=["GET", "POST"])
    */
    public function myAction(ServerRequestInterface $request, ResponseInterface $response, $arg1, $arg2)
    { ... }
}

```

Rules:

- Controller classes' names MUST end with the suffix "Controller", i.e. `MyTestController`.
- Controller constructors MAY ONLY have `App` or `ContainerInterface` dependencies.
- `@Route` annotation needs at least the route (first argument in quotes)
- Classes MAY have the `@Route` annotation specifying only the prefix for the whole class' actions
- Methods MAY specify the `@Route` annotation. Optional values are:
    - `name`: the name of the route (in order to be called somewhere else)
    - `methods`: to specify at which methods the action responds. Default: all
- Methods can specify any argument written in the route (as placeholders) and are mapped per-name, case sensitive. This means that if there is a route placeholder `{myArgument}`, there MAY be a method's argument `$myArgument`. If there is a method's argument called `$myArgument` there MUST be a `{myArgument}` route placeholder. Exceptions are the `ServerRequestInterface`, `ResponseInterface` and `ContainerInterface` arguments, that MAY be called with any variable name and are always the standard `$request`, `$response` and `$app->getContainer()` Slim3 objects.

---

Setup
-----

[](#setup)

```
