RouterRegister Help

Router Register

RouterRegister allows routes to be defined in application source files using PHP Attributes amd Enumerations.

There are a number of benefits of defining and registering routes using RouterRegister:

  • Self-documenting code: it's clear that a method corresponds to a given route and what parameters, hosts, and middleware apply to the route.

  • Single point of truth: each route, its URI and name is defined in an enumeration, making maintenance simpler and providing IDE code completion.

  • Simplifies development and eliminates typos: IDE code completion for routes works when generating URLs as well.

RouterRegister parses generates an internal representation of the defined groups and routes from the Attributes and Enumerations. A framework specific Writer object then creates the router configuration files.

Installation

RouterRegister is installed as a dependency of a framework specific RouterRegister Writer package.

Usage

Using RouterRegister involves:

  1. Creating Middleware Attributes (if required)

  2. Defining groups (if required)

  3. Defining routes

  4. Assigning groups and routes in source code

  5. Running RouterRegister to generate router configuration files. This can be from a console command or on an HTTP request; if using the latter, the configuration files should be cached in a production environment.

Last modified: 20 November 2025