Skip to content

Commit

Permalink
Permit zero hops to allow messages visible only in the current reques…
Browse files Browse the repository at this point in the history
…t. Ref: #7

Signed-off-by: Tim Lieberman <[email protected]>
  • Loading branch information
timdev committed Apr 1, 2021
1 parent 460b5ad commit ba318f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/FlashMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/FlashMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit ba318f0

Please sign in to comment.