PHPackages                             tyesty/routing-annotation-reader - 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. tyesty/routing-annotation-reader

ActiveLibrary[API Development](/categories/api)

tyesty/routing-annotation-reader
================================

Controller class annotation reader for collecting routes

1.2.1(7y ago)03.3kMITPHPPHP &gt;=7.1.0

Since Mar 5Pushed 7y agoCompare

[ Source](https://github.com/tyesty/routing-annotation-reader)[ Packagist](https://packagist.org/packages/tyesty/routing-annotation-reader)[ RSS](/packages/tyesty-routing-annotation-reader/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)DependenciesVersions (6)Used By (0)

Routing annotation reader
-------------------------

[](#routing-annotation-reader)

This small class indexes all controller classes in a given set of directories and creates a list of routes out of the action methods.

To ensure that your controller action is indexed, simply add a bunch of docblock to your Controller classes and run the annotation reader.

### Usage

[](#usage)

- In order to be indexed properly, your project must follow the psr-4 namespace convention and all controller classes must have the postfix `Controller`.
- All action methods must have the postfix "Action" in order to be indexed properly
- Then simply annotate the contoller/action routes in your class/method docblocks
- For controller classes, add a `@BaseRoute ` annotation to your class docblock.
- For controller action methods, add a `@Route []  ()` annotation.
- You can add middlewares for either all methods in a particular class or only for a specific method by adding a `@Middleware ` annotation.
- Run the annotation reader as described in the example below. It will then search for controller classes in the given folders and will walk through all the action methods, fetch the docblock comments and create the route array for you.

#### Creating a Reader object

[](#creating-a-reader-object)

ParameterTypeDefaultDescription$directoriesarray\[\]List of directories that contain the controller classes. These directories are traversed recursively.$route\_log?stringnullThe log file in which the routing documentation shall be written. If set to null, then no documentation is generated. If `$log_function` is set, then this parameter will be ignored.$log\_function?callablenullA function/invokeable class that will be run after the routes have been determined. This can be used for literally everything, but the most common use case is autogenerated routing documentation. The only parameter of the callable is the current `Reader` object.### Example

[](#example)

```
