PHP code example of middlewares / trailing-slash

1. Go to this page and download the library: Download middlewares/trailing-slash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

middlewares / trailing-slash example snippets


$dispatcher = new Dispatcher([
	(new Middlewares\TrailingSlash(true))
		->redirect()
]);

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

//Removes the slash, so /post/23/ is converted to /post/23
$slash = new Middlewares\TrailingSlash();

//Force the slash, so /post/23 is converted to /post/23/
$slash = new Middlewares\TrailingSlash(true);

$responseFactory = new MyOwnResponseFactory();

//Simply removes the slash
$slash = new Middlewares\TrailingSlash();

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

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