firewox/f-routes

Library for generating slim routes using PHP attributes

v2.0.0 2021-03-16 18:45 UTC

This package is not auto-updated.

Last update: 2024-05-08 06:59:32 UTC


README

This project has been created for the purpose of:

  1. Simplifying creation of Slim routes
  2. Making routes more readable and easier to understand

Getting Started

  1. Install composer package
  2. Register the route processor
  3. Add controllers
  4. Add middleware

Installation

composer require firewox/f-routes

Registering Route Processor

Put the following code into your index.php:

<?php

use DI\Container;
use Firewox\FRoutes\Factory;

$processor = Factory::create(
  new Container(),
  'Firewox\Tests\Controllers'       /* Namespace for controllers */
);

// Run the Slim app 
$processor->getApp()->run();

If you also have middleware for Slim you can include the middleware namespace as follows:

<?php

use DI\Container;
use Firewox\FRoutes\Factory;

$processor = Factory::create(
  new Container(),
  'Firewox\Tests\Controllers',       /* Namespace for controllers */
  'Firewox\Tests\Middlewares'       /* Namespace for middlewares */
);

// Run the Slim app 
$processor->getApp()->run();

Creating route controllers

Blah blah blah

  1. Application routes
  2. Group routes

Creating middleware

Blah blah blah

  1. Application middleware
  2. Group middleware
  3. Route middleware

Attributes Documentation

Controller Attribute

PropertyDescriptionPossible Values
isGroupGroup controller or not. (Default: false)true or false
pathPatternSlim compliant route path. (Default: '')Any valid path
middlewaresSlim middleware class names. Not necessarily marked with Middleware attribute. (Default: [])0 or more class names

Route Attribute

PropertyDescriptionPossible Values
methodsValid slim HTTP verbs. (Required)POST, PUT, GET, PATCH, DELETE, OPTIONS
pathPatternSlim compliant route path. (Required)Any valid path
nameName of the route. (Default: null)Any valid name
defaultApplication level default route or not. **(Default: false). Ex. 404 default route.true or false
priorityOrder in which route should be registered. Multiple routes can have the same number. (Default: 0)Any number as needed
middlewaresList of middleware class names. Not necessarily marked with Middleware attribute. (Default: [])0 or more class names
groupController class name. The controller class must be marked with Controller attribute with isGroup = true. (Default: null)Valid class name

Middleware Attribute

PropertyDescriptionPossible Values
priorityOrder in which middleware should be registered. Multiple middleware can have the same number. (Default: 0)Any number as needed