diff --git a/src/FlashMessages.php b/src/FlashMessages.php index c2d65ec..e910f88 100644 --- a/src/FlashMessages.php +++ b/src/FlashMessages.php @@ -92,12 +92,17 @@ public function flash(string $key, $value, int $hops = 1): void * using this method, you may make the value available during the current * request as well. * + * If you want the value to be visible only in the current request, you may + * pass zero as the third argument. + * * @param mixed $value */ public function flashNow(string $key, $value, int $hops = 1): void { $this->currentMessages[$key] = $value; - $this->flash($key, $value, $hops); + if ($hops > 0) { + $this->flash($key, $value, $hops); + } } /** diff --git a/test/FlashMessagesTest.php b/test/FlashMessagesTest.php index 530f9bc..ce2627f 100644 --- a/test/FlashMessagesTest.php +++ b/test/FlashMessagesTest.php @@ -365,7 +365,14 @@ public function testCreationAggregatesThrowsExceptionIfInvalidNumberOfHops() $this->anything() ); + $flash = FlashMessages::createFromSession($this->session); + $flash->flash('test', 'value', 0); + } + + public function testFlashNowAcceptsZeroHops() + { $flash = FlashMessages::createFromSession($this->session); $flash->flashNow('test', 'value', 0); + $this->assertSame('value', $flash->getFlash('test')); } }