HttpMethodRoutesTrait uses trait:short
Provides the per-verb route factory methods shared by composite routes.
Building on HasRouteTrait, this trait exposes one helper per HTTP verb
(get(), post(), put(), patch(), delete(), list(), count(),
options()) that appends the matching HttpMethodRoute
subclass to a routes accumulator, but only when the corresponding
RouteFlag is enabled. Default controller method
names can be overridden globally through HttpMethodRoutesTrait::initializeMethods()
or per call.
Tags
Table of Contents
Properties
- $delete : string|null
- $flags : int
- Bitmask representing enabled routes
- $get : string|null
- $list : string|null
- $patch : string|null
- $post : string|null
- $put : string|null
Methods
- count() : void
- Generates a special GET count route reference.
- delete() : void
- Generates a new DELETE route reference.
- describeFlags() : string
- Get a human-readable description of enabled routes
- disableFlags() : static
- Disable specific route flags
- enableFlags() : static
- Enable specific route flags
- get() : void
- Generates a new GET route reference.
- hasCount() : bool
- Check if COUNT route is enabled
- hasDelete() : bool
- Check if DELETE route is enabled
- hasDeleteMultiple() : bool
- Check if DELETE_MULTIPLE is enabled
- hasGet() : bool
- Check if GET route is enabled
- hasList() : bool
- Check if LIST route is enabled
- hasPatch() : bool
- Check if PATCH route is enabled
- hasPost() : bool
- Check if POST route is enabled
- hasPut() : bool
- Check if PUT route is enabled
- initializeFlags() : static
- Initialize the internal flags.
- initializeMethods() : static
- Initializes or overrides HTTP method handlers based on the given init array.
- list() : void
- Generates a new GET (LIST) route reference.
- method() : void
- Instantiates a route of the given class and appends it to the accumulator.
- options() : void
- Generates a new OPTIONS route reference.
- patch() : void
- Generates a new PATCH route reference.
- post() : void
- Generates a new POST route reference.
- put() : void
- Generates a new PUT route reference.
Properties
$delete
public
string|null
$delete
= null
$flags
Bitmask representing enabled routes
public
int
$flags
= \oihana\routes\enums\RouteFlag::DEFAULT
$get
public
string|null
$get
= null
$list
public
string|null
$list
= null
$patch
public
string|null
$patch
= null
$post
public
string|null
$post
= null
$put
public
string|null
$put
= null
Methods
count()
Generates a special GET count route reference.
public
count(array<string|int, mixed> &$routes, string $route[, string|null $method = HttpMethod::count ]) : void
Only appended when the COUNT flag is enabled; the /count suffix is added
automatically to the given route.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The base route path.
- $method : string|null = HttpMethod::count
-
The controller method to invoke (defaults to the
countmethod).
delete()
Generates a new DELETE route reference.
public
delete(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the DELETE flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured delete method).
describeFlags()
Get a human-readable description of enabled routes
public
describeFlags() : string
Return values
string —Description of enabled routes
disableFlags()
Disable specific route flags
public
disableFlags(int $flags) : static
Parameters
- $flags : int
-
Flags to disable
Return values
static —Returns the current instance for method chaining.
enableFlags()
Enable specific route flags
public
enableFlags(int $flags) : static
Parameters
- $flags : int
-
Flags to enable
Return values
static —Returns the current instance for method chaining.
get()
Generates a new GET route reference.
public
get(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the GET flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured get method).
hasCount()
Check if COUNT route is enabled
public
hasCount() : bool
Return values
bool —true if the COUNT route is enabled, false otherwise.
hasDelete()
Check if DELETE route is enabled
public
hasDelete() : bool
Return values
bool —true if the DELETE route is enabled, false otherwise.
hasDeleteMultiple()
Check if DELETE_MULTIPLE is enabled
public
hasDeleteMultiple() : bool
Return values
bool —true if the DELETE_MULTIPLE route is enabled, false otherwise.
hasGet()
Check if GET route is enabled
public
hasGet() : bool
Return values
bool —true if the GET route is enabled, false otherwise.
hasList()
Check if LIST route is enabled
public
hasList() : bool
Return values
bool —true if the LIST route is enabled, false otherwise.
hasPatch()
Check if PATCH route is enabled
public
hasPatch() : bool
Return values
bool —true if the PATCH route is enabled, false otherwise.
hasPost()
Check if POST route is enabled
public
hasPost() : bool
Return values
bool —true if the POST route is enabled, false otherwise.
hasPut()
Check if PUT route is enabled
public
hasPut() : bool
Return values
bool —true if the PUT route is enabled, false otherwise.
initializeFlags()
Initialize the internal flags.
public
initializeFlags([array<string|int, mixed>|int $init = [] ]) : static
Parameters
- $init : array<string|int, mixed>|int = []
-
A raw bitmask, an init array carrying a
flagsinteger, or a legacy boolean-array configuration.
Return values
static —Returns the current instance for method chaining.
initializeMethods()
Initializes or overrides HTTP method handlers based on the given init array.
public
initializeMethods([array<string|int, mixed> $init = [] ]) : static
Parameters
- $init : array<string|int, mixed> = []
-
Initialization or override parameters, keyed by HTTP verb.
Return values
static —Returns the current instance for method chaining.
list()
Generates a new GET (LIST) route reference.
public
list(array<string|int, mixed> &$routes, string $route[, string|null $method = HttpMethod::list ]) : void
Only appended when the LIST flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = HttpMethod::list
-
The controller method to invoke (defaults to the
listmethod).
method()
Instantiates a route of the given class and appends it to the accumulator.
public
method(string $clazz, array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
- $clazz : string
-
The fully qualified route class to instantiate (must extend Route).
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke for this route, if any.
Tags
options()
Generates a new OPTIONS route reference.
public
options(array<string|int, mixed> &$routes, string $route[, bool $flag = true ]) : void
The route is only appended when $flag is true, which lets callers
conditionally expose the OPTIONS verb depending on the other enabled routes.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $flag : bool = true
-
Whether the OPTIONS route should actually be created (default
true).
Tags
patch()
Generates a new PATCH route reference.
public
patch(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the PATCH flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured patch method).
post()
Generates a new POST route reference.
public
post(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the POST flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured post method).
put()
Generates a new PUT route reference.
public
put(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the PUT flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured put method).