sirix / inertia-psr15-mezzio-flash
Mezzio flash-message bridge for inertia-psr15
Package info
github.com/sirix777/inertia-psr15-mezzio-flash
pkg:composer/sirix/inertia-psr15-mezzio-flash
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- mezzio/mezzio-flash: ^1.10
- psr/container: ^1.0 || ^2.0
- psr/http-message: ^1.1 || ^2.0
- sirix/inertia-psr15: ^3.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- laminas/laminas-diactoros: ^3.6.0
- mezzio/mezzio-session: ^1.0
- phpunit/phpunit: ^10.5 || ^11.5
README
Storage-neutral Mezzio flash-message integration for sirix/inertia-psr15 3.x. It adapts Mezzio\Flash\FlashMessagesInterface to the core public flash-provider contract. It does not install middleware, select a session backend, transform payloads, or write logs.
Installation
composer require sirix/inertia-psr15-mezzio-flash
The package is auto-discovered by laminas-component-installer. Ensure the session and flash middleware run before Inertia for every applicable path:
$app->pipe(\Mezzio\Session\SessionMiddleware::class); $app->pipe(\Mezzio\Flash\FlashMessageMiddleware::class); $app->pipe(\Sirix\InertiaPsr15\Middleware\InertiaMiddleware::class);
The default request attribute is FlashMessageMiddleware::FLASH_ATTRIBUTE (flash). Missing or incorrectly typed attributes fail fast with a typed bridge exception, which usually means the pipeline order or route coverage is incorrect.
Usage
For a response rendered in the same request, use the core API:
$inertia->flash('message', 'Profile saved'); return $inertia->render('Profile/Edit', ['profile' => $profile]);
For post-redirect-get, queue the flash value before returning a redirect:
$inertia->flash(['message' => 'User created', 'userId' => $user->id]); return new \Laminas\Diactoros\Response\RedirectResponse('/users/' . $user->id);
Incoming Mezzio messages and direct values are exposed in Inertia v3's top-level page.flash; they are not copied to props.flash. On control responses (409 with X-Inertia-Location or X-Inertia-Redirect), the core persists pending direct data before this bridge prolongs incoming messages.
Configuration
The configuration provider registers only InertiaFlashProviderInterface and defaults to the flash request attribute. To use a different attribute name:
return [ 'inertia_psr15_mezzio_flash' => [ 'request_attribute' => 'application_flash', ], ];
The value must be a non-empty, control-character-free string. The adapter returns the native Mezzio payload unchanged; core validates safe keys and serializability.
Contributing
Run all checks with:
composer check
See CONTRIBUTING.md, SECURITY.md, and CHANGELOG.md.