-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlertManager.php
104 lines (91 loc) · 1.8 KB
/
AlertManager.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
* This file is part of the Silvestra package.
*
* (c) Tadas Gliaubicas <tadcka89@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silvestra\Component\Notification;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
/**
* @author Tadas Gliaubicas <tadcka89@gmail.com>
*
* @since 11/8/14 12:19 PM
*/
class AlertManager
{
const FLASH_BAG_KEY = 'silvestra_notification_alerts';
/**
* @var Alert
*/
private $alert;
/**
* @var FlashBagInterface
*/
private $flashBag;
/**
* Constructor.
*
* @param FlashBagInterface $flashBag
*/
public function __construct(FlashBagInterface $flashBag)
{
$this->flashBag = $flashBag;
}
/**
* Set alert.
*
* @param Alert $alert
*/
public function setAlert(Alert $alert)
{
$this->alert = $alert;
}
/**
* Set flash alert.
*
* @param Alert $alert
*/
public function setFlashAlert(Alert $alert)
{
$this->flashBag->set(self::FLASH_BAG_KEY, $alert->all());
}
/**
* Create alert.
*
* @return Alert
*/
public function create()
{
return new Alert();
}
/**
* Get alert.
*
* @return Alert
*/
public function getAlert()
{
return $this->alert;
}
/**
* Get flash alerts.
*
* @return array
*/
public function getFlashAlerts()
{
return $this->flashBag->get(self::FLASH_BAG_KEY);
}
/**
* Check for flash alerts.
*
* @return bool
*/
public function hasFlashAlerts()
{
return 0 < count($this->flashBag->peek(self::FLASH_BAG_KEY));
}
}