forked from jasny/session-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlashTrait.php
More file actions
39 lines (32 loc) · 902 Bytes
/
Copy pathFlashTrait.php
File metadata and controls
39 lines (32 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace Jasny\Session\Flash;
use Jasny\Session\SessionInterface;
/**
* Trait for flash messages.
*/
trait FlashTrait
{
protected FlashBag $flashBag;
/**
* Add a flash message.
*
* @param string $type flash type, eg. 'error', 'notice' or 'success'
* @param string $message flash message
* @param string $contentType mime, eg 'text/plain' or 'text/html'
*/
public function flash(string $type, string $message, string $contentType = 'text/plain'): void
{
$this->flashes()->add($type, $message, $contentType);
}
/**
* Get the bag with flash messages.
*/
public function flashes(): FlashBag
{
/** @var SessionInterface $session */
$session = $this;
$this->flashBag = $this->flashBag->withSession($session);
return $this->flashBag;
}
}