t0mmy742 / trailing-slash-middleware
A PSR-15 middleware to remove trailing slash in URI
1.1.0
2020-12-07 20:08 UTC
Requires
- php: ^8.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.59
- phpstan/phpstan-deprecation-rules: ^0.12.5
- phpstan/phpstan-phpunit: ^0.12.16
- phpstan/phpstan-strict-rules: ^0.12.5
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
- thecodingmachine/phpstan-strict-rules: ^0.12.1
README
This middleware remove trailing slash from URI. It implements PSR-15 MiddlewareInterface and need a PSR-17 ResponseFactory to work.
Installation
$ composer require t0mmy742/trailing-slash-middleware
Usage
<?php use t0mmy742\Middleware\TrailingSlashMiddleware; $responseFactory = new \Your\PSR17\ResponseFactory(); $middleware = new TrailingSlashMiddleware($responseFactory);
If path does not contain trailing slash, or if it is home ('/'), it does nothing. Otherwise, if it is a GET request, it creates a new Response with a 301 Permanent Redirect to the new URI (if is is not a GET request, it just handles request with new URI).