26 lines
782 B
PHP
26 lines
782 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Htmx;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Response that makes htmx perform a full page navigation.
|
|
*
|
|
* htmx never follows a normal 3xx itself -- the browser does, transparently, and htmx then swaps
|
|
* whatever the final destination returned, which is a whole page in the wrong place. So a redirect
|
|
* has to be handed to htmx as an instruction instead: a 200 carrying HX-Redirect.
|
|
*
|
|
* Anything returning this from an event listener must also call
|
|
* ExceptionEvent::allowCustomResponseCode(), or the kernel overwrites the 200.
|
|
*/
|
|
class HxRedirectResponse extends Response
|
|
{
|
|
public function __construct(string $url)
|
|
{
|
|
parent::__construct('', Response::HTTP_OK, ['HX-Redirect' => $url]);
|
|
}
|
|
}
|