From 66f1724d426f9caad80b414f3dde74cfbb3c47f4 Mon Sep 17 00:00:00 2001 From: Hari K T Date: Tue, 8 Sep 2026 18:41:51 +0530 Subject: [PATCH] Add getFlashAll() and getFlashNextAll() to FlashSegmentInterface There was no way to read flash values without knowing their keys in advance, so rendering a list of flash messages meant reaching into $_SESSION directly. ManageableSegmentInterface::getSegment() covers this for plain values; these two do the same for the current and next request. Neither takes an alternative value. Unlike getFlash(), an all-getter has no "set to null" case to distinguish from "not set", so the empty array is the only sensible default. Proposed for Aura.Session by Jake Johns in 2016 (auraphp/Aura.Session#47 and #52) and deferred because it changed a published interface; the 7.0 line is still a pre-release, so the change is free to make now. --- CHANGELOG.md | 7 ++++++- README.md | 9 +++++++-- src/FlashSegmentInterface.php | 20 ++++++++++++++++++++ tests/InterfaceContractTest.php | 4 ++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 560bdfd..6af4d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # CHANGELOG -## 7.0.0 +## 7.0.0-beta2 + +- (ADD) `Aura\Session_Interface\FlashSegmentInterface` gains `getFlashAll()` and `getFlashNextAll()`, which return every flash value for the current or the next request, so consumers can render flash messages without knowing the keys. Neither takes an alternative value, and both return an empty array when nothing is set. +- (BRK) Implementations written against `7.0.0-beta1` must add those two methods. + +## 7.0.0-beta1 Initial release. diff --git a/README.md b/README.md index 3aac1a0..2597b29 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,13 @@ The contract for managing a segment as a whole: ### `Aura\Session_Interface\FlashSegmentInterface` The contract for "flash" values (available for the next request, and/or the -current one): `setFlash()`, `getFlash()`, `clearFlash()`, `getFlashNext()`, -`setFlashNow()`, `clearFlashNow()`, and `keepFlash()`. +current one): `setFlash()`, `getFlash()`, `getFlashAll()`, `clearFlash()`, +`getFlashNext()`, `getFlashNextAll()`, `setFlashNow()`, `clearFlashNow()`, and +`keepFlash()`. + +The two all-getters return every flash value for the current or the next +request, so a consumer can render them without knowing the keys in advance; +both return an empty array when there is nothing set. Each of these is a separate interface so that consumers that only read and write plain values do not have to depend on whole-segment management or flash diff --git a/src/FlashSegmentInterface.php b/src/FlashSegmentInterface.php index 6739bdf..7d62570 100644 --- a/src/FlashSegmentInterface.php +++ b/src/FlashSegmentInterface.php @@ -46,6 +46,16 @@ public function setFlash(string $key, mixed $val): void; */ public function getFlash(string $key, mixed $alt = null): mixed; + /** + * + * Gets all the flash values for the *current* request. + * + * @return array All the flash values for the current request; empty when + * there are none. + * + */ + public function getFlashAll(): array; + /** * * Clears flash values for *only* the next request. @@ -68,6 +78,16 @@ public function clearFlash(): void; */ public function getFlashNext(string $key, mixed $alt = null): mixed; + /** + * + * Gets all the flash values for the *next* request. + * + * @return array All the flash values for the next request; empty when + * there are none. + * + */ + public function getFlashNextAll(): array; + /** * * Sets a flash value for the *next* request *and* the current one. diff --git a/tests/InterfaceContractTest.php b/tests/InterfaceContractTest.php index c28ce20..96b1c8c 100644 --- a/tests/InterfaceContractTest.php +++ b/tests/InterfaceContractTest.php @@ -42,8 +42,10 @@ class InterfaceContractTest extends TestCase FlashSegmentInterface::class => [ 'setFlash' => 'void', 'getFlash' => 'mixed', + 'getFlashAll' => 'array', 'clearFlash' => 'void', 'getFlashNext' => 'mixed', + 'getFlashNextAll' => 'array', 'setFlashNow' => 'void', 'clearFlashNow' => 'void', 'keepFlash' => 'void', @@ -114,8 +116,10 @@ public function clear(): void { $this->data = []; } public function remove(?string $key = null): void { $key === null ? $this->data = [] : $this->data[$key] = null; } public function setFlash(string $key, mixed $val): void {} public function getFlash(string $key, mixed $alt = null): mixed { return $alt; } + public function getFlashAll(): array { return []; } public function clearFlash(): void {} public function getFlashNext(string $key, mixed $alt = null): mixed { return $alt; } + public function getFlashNextAll(): array { return []; } public function setFlashNow(string $key, mixed $val): void {} public function clearFlashNow(): void {} public function keepFlash(): void {}