Is it possible to get the number of \Phalcon\Flash per message category

I would like to know if it's possible to get the total number of \Phalcon\Flash message per category Something like

$this->flash->totalError();
$this->flash->totalWarning();
$this->flash->totalNotice();
$this->flash->totalSuccess();


84.5k

No, Phalcon\Flash does not have such functionality. Perphaps you can create your own Flash class implementing that functionality:

class Flash extends Phalcon\Flash\Direct
{
    public function totalError()
    { 
        //...
    }
}


1.5k

I think I found the answer I was seeking

It's possible to do it via the Phalcon\Flash\Session (I think, haven't tested yet, I'm going to edit this comment as soon as I will)

In the doc : http://docs.phalconphp.com/en/latest/api/Phalcon%5Flash%5Session.html

public has (unknown $type)
    bool \Phalcon\Flash\Session::has(string $type)

and

public array getMessages ([string $type], [boolean $remove])
    Returns the messages in the session flasher

So it would be possible to do :

if($this->flashSession->has("error")){
    [...]
}
//or
if(count($this->flashSession->getMessages("error", false)) >= $myVar){
    [...]
}