middlewares / lowercase
A lowercase repository for PSR-15 middleware packages
Requires
- php: ^7.2 || ^8.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- middlewares/utils: ^3.0
- oscarotero/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-09 03:26:52 UTC
README
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
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
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.