/
BanIPEvent.php
92 lines (81 loc) · 1.91 KB
/
BanIPEvent.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
<?php
namespace Concrete\Core\Permission\Event;
use Symfony\Component\EventDispatcher\Event as AbstractEvent;
use Concrete\Core\Utility\IPAddress;
use DateTime;
class BanIPEvent extends AbstractEvent
{
/**
* The IP address that is going to be banned.
*
* @var IPAddress
*/
protected $ipAddress;
/**
* The ban expiration date/time (or null if not expiration).
*
* @var DateTime
*/
protected $banExpiration;
/**
* Should we proceed or the ban has been canceled?
*
* @var bool
*/
protected $proceed = true;
/**
* @param IPAddress $ipAddress the IP address that is going to be banned
* @param DateTime $banExpiration the ban expiration date/time (or null if not expiration)
*/
public function __construct(IPAddress $ipAddress, DateTime $banExpiration = null)
{
$this->ipAddress = $ipAddress;
$this->banExpiration = $banExpiration;
}
/**
* Get the IP address that is going to be banned.
*
* @return IPAddress
*/
public function getIPAddress()
{
return $this->ipAddress;
}
/**
* Get the ban expiration date/time (or null if not expiration).
*
* @return DateTime
*/
public function getBanExpiration()
{
return $this->banExpiration;
}
/**
* Set the ban expiration date/time (or null if not expiration).
*
* @param DateTime $banExpiration
*
* @return static
*/
public function setBanExpiration(DateTime $banExpiration = null)
{
$this->banExpiration = $banExpiration;
return $this;
}
/**
* Cancel the ban.
*/
public function cancelBan()
{
$this->proceed = false;
}
/**
* Should we proceed or the ban has been canceled?
*
* @return bool
*/
public function proceed()
{
return $this->proceed;
}
}