helpers
Table of Contents
Functions
- responsePassthrough() : callable
- Returns a passthrough handler that simply returns the response unchanged.
- withPlaceholder() : string
- Builds a Slim-framework-compatible route by appending a placeholder.
Functions
responsePassthrough()
Returns a passthrough handler that simply returns the response unchanged.
responsePassthrough() : callable
This is useful for routes that don't need to perform any processing, such as OPTIONS requests that only need to return CORS headers or other middleware-handled responses.
Usage Examples
use function oihana\routes\helpers\responsePassthrough;
// Simple OPTIONS route
$app->options('/api/users', responsePassthrough(...));
// HEAD route that mirrors GET
$app->head('/api/users', responsePassthrough(...));
// Any route where middleware handles everything
$app->get('/health', responsePassthrough(...));
Tags
Return values
callable —A PSR-15 compatible request handler that returns the response as-is.
withPlaceholder()
Builds a Slim-framework-compatible route by appending a placeholder.
withPlaceholder(string $route[, string|null $placeholder = null ][, bool $optional = false ][, bool $leadingSlash = true ]) : string
This helper function assembles a base route and a placeholder segment, automatically handling trailing slashes, optional segments, and empty placeholders. It is designed to simplify the creation of dynamic route patterns.
Parameters
- $route : string
-
The base route path (e.g., '/users').
- $placeholder : string|null = null
-
Placeholder name, optionally with regex (e.g., 'id', 'id:[0-9]+', 'params:.*')
- $optional : bool = false
-
If
true, wrap the placeholder in square brackets - $leadingSlash : bool = true
-
If
true, a leading slash/will be prepended to the placeholder (Default true).
Tags
Return values
string —Slim route with placeholder