michaelbiberich / turbolinks-location-middleware
PSR-15 compliant implementation of MiddlewareInterface to insert Turbolinks-Location header into every response
Requires
- php: >=7.4
- psr/http-server-middleware: ^1
Requires (Dev)
- nyholm/psr7: ^1
- pds/skeleton: ^1
- phpunit/phpunit: ^9.3
Provides
This package is auto-updated.
Last update: 2024-11-09 22:58:15 UTC
README
PSR-15 compliant implementation of MiddlewareInterface to insert Turbolinks-Location header into every response
See the Turbolinks documentation on following redirects.
Inspired by code-orange/turbolinks-location.
Table of Contents
Install
Add turbolinks-location-middleware as a dependency to your project with composer.
composer require michaelbiberich/turbolinks-location-middleware ^1
Tests
Tests can be run using PHPUnit, see phpunit.xml.dist.
phpunit --configuration ./phpunit.xml.dist
Code Coverage can be reported as well, eg by using PHPDBG.
phpdbg -qrr ./vendor/bin/phpunit --coverage-text
Composer scripts are available for both tasks.
composer test
composer coverage
A quick way to run these without installing composer can be achieved by using the official composer Docker Image.
Eg
docker run --rm --interactive --tty --volume $PWD:/app composer coverage
Usage
Create a new instance of TurbolinksLocationMiddleware
and Add it to your
dispatcher/route handler/pipe:
<?php require_once __DIR__ . '/../vendor/autoload.php'; use MichaelBiberich\TurbolinksLocationMiddleware\TurbolinksLocationMiddleware; $turbolinksLocation = new TurbolinksLocationMiddleware; // --- // Example: Slim 4 application middleware // see: http://www.slimframework.com/docs/v4/concepts/middleware.html // --- use Slim\Factory\AppFactory; $app = AppFactory::create(); // ... $app->add($turbolinksLocation); // --- // Example: Mezzio middleware pipe // see: https://docs.laminas.dev/laminas-stratigility/v3/middleware/ // --- use Laminas\Stratigility\MiddlewarePipe; use function Laminas\Stratigility\middleware; $app = new MiddlewarePipe(); // ... $app->pipe(middleware($turbolinksLocation));
Contributing
Feel free to dive in! Open an issue or submit PRs.
License
BSD-3-Clause © Michael Biberich