Skip to content

[4.x] Add "All Getters" for "Flash" values and "Add" - #52

Closed
jakejohns wants to merge 4 commits into
auraphp:4.xfrom
jakejohns:feature/3x-flash-all
Closed

jakejohns wants to merge 4 commits into
auraphp:4.xfrom
jakejohns:feature/3x-flash-all

Conversation

@jakejohns

Copy link
Copy Markdown
Member

This is just #47 for 3.x.
It looks like there was already a getAll equivalent: getSegment.

@jakejohns jakejohns changed the title [3.x] Add All getters for "Flash" values [3.x] Add "All Getters" for "Flash" values Apr 10, 2016
Comment thread src/Segment.php
*
*/
public function getFlashAll($alt = array())
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't flash all means flash now + next ?

@jakejohns

Copy link
Copy Markdown
Member Author

Fair point, @harikt. Perhaps the name is a little terse.
Perhaps getAllCurrentFlash(), and getAllNextFlash() would be better?

@jakejohns
jakejohns force-pushed the feature/3x-flash-all branch from 3a638f7 to 743d5e2 Compare April 11, 2016 16:43
@harikt

harikt commented Apr 11, 2016

Copy link
Copy Markdown
Member

Let's wait to hear from pmjones thoughts.

@jakejohns
jakejohns force-pushed the feature/3x-flash-all branch from 743d5e2 to cc0f489 Compare April 11, 2016 17:04
- Segment::getFlashAll();
- Segment::getFlashNextAll();
@jakejohns
jakejohns force-pushed the feature/3x-flash-all branch from cc0f489 to 5c7ca60 Compare April 11, 2016 17:31
@jakejohns jakejohns changed the title [3.x] Add "All Getters" for "Flash" values [3.x] Add "All Getters" for "Flash" values and "Add" Apr 11, 2016
@jakejohns

Copy link
Copy Markdown
Member Author

I added "add" methods here as well.
I should have perhaps done this as a separate PR, but the intention is that the getAll and add stuff would be complimentary.

@harikt, I just noticed that you said to wait on pmj, but i'm pretty sure you're right, so I had already gone and changed it. Obviously can always change to something else.

As an illustration of my intended use case:

<?php
// @codingStandardsIgnoreFile

abstract class MyAbstractResponder
{
    protected $msgSegment = 'My\\Messages';

    protected function addMessage($msg, $level = 'info')
    {
        $this->getSession()
            ->getSegment($this->msgSegment)
            ->addFlash(['lvl' => $level, 'msg' => $msg]);
    }

    protected function getMessages()
    {
        return $this->getSession()
            ->getSegment($this->msgSegment)
            ->getAllCurrentFlash([]);
    }

    protected function render()
    {
        $view = $this->getView();
        $view->addData(['messages' => $this->getMessages()]);
        $this->response->getBody()->write($view());
    }

    protected function updated()
    {
        $this->addMessage('Successfully updated thing', 'success');
        $this->redirect();
    }

    //...
}

@harikt
harikt changed the base branch from 3.x to 4.x September 13, 2023 06:17
@harikt harikt changed the title [3.x] Add "All Getters" for "Flash" values and "Add" [4.x] Add "All Getters" for "Flash" values and "Add" Sep 13, 2023
@harikt

harikt commented Sep 23, 2023

Copy link
Copy Markdown
Member

@jakejohns Sorry that this is not merged. I am going to release a 4.x for session to make it compatible with 8.x . Newer feature is not incorported for now. So this is currently put on hold.

harikt added a commit that referenced this pull request Sep 8, 2026
Reading flash values required knowing their keys in advance, so
rendering a list of flash messages meant reaching into $_SESSION
directly. getSegment() already covers this for plain values; these two
do the same for the current and the next request.

Neither takes an alternative value, following getSegment() rather than
the key-based getters: $alt exists to tell "key not set" apart from "key
set to null", and an all-getter has no such ambiguity. Both return an
empty array when nothing is set, so the result is always iterable.

Proposed by Jake Johns in #47 and #52, and deferred because it changed a
published interface.
@harikt

harikt commented Sep 8, 2026

Copy link
Copy Markdown
Member

Thanks for this, @jakejohns, and sorry it sat for so long.

The "all getters" half has now shipped on 7.x in #107, essentially as you
proposed it here:

$segment->getFlashAll();     // every flash value in the current request
$segment->getFlashNextAll(); // every flash value set for the next request

The blocker you identified back in #47 — "the change in the interface is a
breaking change"
— was the real thing holding it up, and it only cleared
recently. The contracts now live in a separate aura/session-interface package,
and its 7.0 line was still a pre-release, so the methods could be added to
FlashSegmentInterface at no cost (auraphp/Aura.Session_Interface#3, released
in 7.0.0-beta2). Had we waited for 7.0.0 final it would have been an 8.0 item
again.

Two deliberate differences from the patch here:

  • Naming. getFlashAll() / getFlashNextAll(), the names from your original
    Add "All" getters to segment #47, rather than getAllCurrentFlash() / getAllFlashNext(). They group with
    the existing getFlash() / getFlashNext() pair. (The README in this PR
    already said getFlashAll(), so I think this was where you landed too.)
  • No $alt parameter. In this library $alt only appears on key-based
    getters, where it separates "key not set" from "key set to null";
    getSegment(), the whole-collection getter, has none. An all-getter has no
    such ambiguity — and the returned array preserves null-valued keys anyway, so
    array_key_exists() recovers the distinction. Both return array, empty when
    nothing is set, so the result is always safe to iterate.

The add() / addFlash() / addFlashNow() half I left out. Appending with a
numeric key into the same array that holds string keys makes getSegment()'s
return shape unpredictable — the test in this PR shows it returning
array('foo' => 'bar', 'baz' => 'dib', 'qux') — and set() with an explicit
array covers the same ground with a shape callers can reason about. If you still
want appending, a separate issue for a Symfony-style add($type, $value) that
appends within a named bucket would be a better-defined starting point, and
worth discussing on its own merits.

Closing this one, since 4.x is long past and the work landed on 7.x. The
changelog entry credits you. Thanks again for the original proposal — it was
right, it just needed the interface split to happen first.

@harikt harikt closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants