Download the PHP package opsway/slim-attribute-router without Composer
On this page you can find all versions of the php package opsway/slim-attribute-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opsway/slim-attribute-router
More information about opsway/slim-attribute-router
Files in opsway/slim-attribute-router
Package slim-attribute-router
Short Description Slim attribute router with support of groups and middlewares
License MIT
Informations about the package slim-attribute-router
slim-attribute-router
Slim attribute router
This package allows you to add routes to your slim4 (https://www.slimframework.com) application using attributes.
Features
- Route methods support
- Route name support
- Route group support
- Middlewares support
Installation
This package can be installed using Composer
Navigate into your project's root directory and execute the bash command shown below
Enabling the Attribute Router
Attribute router extends slims default RouteCollector, all you need to do is instantiate attribute router and pass it on to AppFactory. First parameter is array of namespace parts of app. It will be used for filtering classes in which search of parameters will go on.
Attribute signature
#[Route({methods}, {path}[[, {group}][, {name}][, {isDeprecated}]])]
Parameter | Example | Description |
---|---|---|
{methods} | ['GET', 'POST'] | (array) The allowed HTTP request methods |
{path} | '/hello/{parameter}' | (string) The route pattern |
{group} | 'group' | (string) The group name |
{name} | 'route.Name' | (string) The name of the route |
{isDeprecated} | 'false' | (bool) Flag if route is deprecated |
- The "methods" parameter is required and must be not empty
- The "path" parameter is required and must be not empty
- Rest of parameters are optional
#[Group({name} [[, {classes}]])]
Parameter | Example | Description |
---|---|---|
{name} | '/api' | (string) The group name |
{classes} | ['Middleware::class'] | (array) Middlewares class names |
- The "name" parameter is required and must be compatible with URI string requirements
- The "classes" parameter is optional. List of classes implementing Psr\Http\Server\MiddlewareInterface
#[Middlewares({firstClass} [, {secondClass}])]
Parameter | Example | Description |
---|---|---|
{firstClass} | ['Middleware::class'] | (string) Middleware class name |
- The "firstClass" parameter is required and must class name of class that implements Psr\Http\Server\MiddlewareInterface
- The "secondClass" and all other parameters is optional.
- All arguments of constructor are converted to an array of middleware classes. It should be at least one middleware class
Specifying attributes examples
Example specifying route with name and group parameters at class level
Example specifying route without additional parameters at method level
Example specifying group with middlewares at class level