Oihana PHP System

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
author

Marc Alcaraz (ekameleon)

since
1.0.0
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
example
// Placeholder requis simple
withPlaceholder('/users', 'id');
// -> '/users/{id}'

// Placeholder requis avec une contrainte regex
withPlaceholder('/articles', 'slug:[a-z0-9-]+');
// -> '/articles/{slug:[a-z0-9-]+}'

// Placeholder optionnel
withPlaceholder('/search', 'query', true);
// -> '/search[/{query}]'

// Placeholder "catch-all" optionnel pour capturer plusieurs segments
withPlaceholder('/files', 'path:.*', true);
// -> '/files[/{path:.*}]'

// Gère correctement le slash final sur la route de base
withPlaceholder('/products/', 'sku');
// -> '/products/{sku}'

// Cas d'un placeholder vide ou null
withPlaceholder('/home', null);
// -> '/home'

// Sans ajout de slash initial (cas d'usage avancé)
withPlaceholder('/user-', 'id', false, false);
// -> '/user-{id}'
Return values
string

Slim route with placeholder


        
On this page

Search results