Aura.Session icon indicating copy to clipboard operation
Aura.Session copied to clipboard

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

Open jakejohns opened this issue 8 years ago • 4 comments

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

jakejohns avatar Apr 10 '16 19:04 jakejohns

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

jakejohns avatar Apr 11 '16 16:04 jakejohns

Let's wait to hear from pmjones thoughts.

harikt avatar Apr 11 '16 17:04 harikt

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();
    }

    //...
}

jakejohns avatar Apr 11 '16 17:04 jakejohns

@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 avatar Sep 23 '23 11:09 harikt