Neuron-PHP

RouteGroup

Route group attribute for defining shared settings for all routes in a controller.

This attribute is applied at the class level and affects all route attributes within that controller. It allows you to define common prefixes and filters that will be inherited by all routes.

Tags
example
#[RouteGroup(prefix: '/admin', filters: ['auth'])]
class UsersController
{
    #[Get('/users')]  // Becomes /admin/users with 'auth' filter
    public function index() { }

    #[Post('/users', filters: ['csrf'])]  // Becomes /admin/users with ['auth', 'csrf'] filters
    public function store() { }
}
Attributes
#[Attribute]
\Attribute::TARGET_CLASS

Table of Contents

Properties

$filters  : array<string|int, mixed>
$prefix  : string

Methods

__construct()  : mixed
applyPrefix()  : string
Apply group settings to a route path
getFilters()  : array<string|int, mixed>
Get the group filters
getPrefix()  : string
Get the route prefix
mergeFilters()  : array<string|int, mixed>
Merge group filters with route filters

Properties

$filters read-only

public array<string|int, mixed> $filters = []

Methods

__construct()

public __construct([string $prefix = '' ][, array<string|int, mixed> $filters = [] ]) : mixed
Parameters
$prefix : string = ''

Path prefix to prepend to all routes (e.g., '/admin')

$filters : array<string|int, mixed> = []

Filters to apply to all routes in this group

applyPrefix()

Apply group settings to a route path

public applyPrefix(string $routePath) : string
Parameters
$routePath : string

The route path from the method attribute

Return values
string

The full path with prefix applied

getFilters()

Get the group filters

public getFilters() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPrefix()

Get the route prefix

public getPrefix() : string
Return values
string

mergeFilters()

Merge group filters with route filters

public mergeFilters(array<string|int, mixed> $routeFilters) : array<string|int, mixed>
Parameters
$routeFilters : array<string|int, mixed>

Filters from the route attribute

Return values
array<string|int, mixed>

Combined filters (group filters first, then route filters)


        
On this page

Search results