middlewares/lowercase

A lowercase repository for PSR-15 middleware packages

v1.0.0 2021-04-08 19:25 UTC

This package is auto-updated.

Last update: 2024-11-09 03:26:52 UTC


README

Latest Version on Packagist Software License Testing Total Downloads

Middleware to set the uri path to lowercase. For example, /Foo/Bar/ is converted to /foo/bar. Useful if you define your routes as lowercase and want to make your routes case insensitive.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/lowercase.

composer require middlewares/lowercase

Example

$dispatcher = new Dispatcher([
    (new Middlewares\Lowercase())
        ->redirect()
        ->attribute('before-lowercase-uri')
]);

$response = $dispatcher->dispatch(new ServerRequest());

Usage

redirect

If the path must be converted to lowercase, this option returns a 301 response redirecting to the new lowercase path. Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface that will be used to create the redirect response. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$responseFactory = new MyOwnResponseFactory();

//Simply set the path to lowercase
$lowercase = new Middlewares\Lowercase();

//Returns a redirect response to the new path
$lowercase = (new Middlewares\Lowercase())->redirect();

//Returns a redirect response to the new path using a specific response factory
$lowercase = (new Middlewares\Lowercase())->redirect($responseFactory);

attribute

If the path must be converted to lowercase, this method will store the original path in an atrribute.

// Save the original non-lowercase uri in the custom attribute "pre-lowercase-path"
$lowercase = (new Middlewares\Lowercase())->attribute('before-lowercase-uri');

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.