1
|
|
|
<?php namespace Arcanedev\SpamBlocker\Entities; |
2
|
|
|
|
3
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
4
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
5
|
|
|
use JsonSerializable; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Spammer |
9
|
|
|
* |
10
|
|
|
* @package Entities |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Spammer implements Arrayable, Jsonable, JsonSerializable |
14
|
|
|
{ |
15
|
|
|
/* ----------------------------------------------------------------- |
16
|
|
|
| Properties |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
protected $host; |
22
|
|
|
|
23
|
|
|
/** @var bool */ |
24
|
|
|
protected $blocked; |
25
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
27
|
|
|
| Constructor |
28
|
|
|
| ----------------------------------------------------------------- |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Spammer constructor. |
33
|
|
|
* |
34
|
|
|
* @param string $host |
35
|
|
|
* @param bool $blocked |
36
|
|
|
*/ |
37
|
120 |
|
public function __construct($host, $blocked) |
38
|
|
|
{ |
39
|
120 |
|
$this->setHost($host); |
40
|
120 |
|
$this->setBlocked($blocked); |
41
|
120 |
|
} |
42
|
|
|
|
43
|
|
|
/* ----------------------------------------------------------------- |
44
|
|
|
| Getters & Setters |
45
|
|
|
| ----------------------------------------------------------------- |
46
|
|
|
*/ |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the host url. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
117 |
|
public function host() |
54
|
|
|
{ |
55
|
117 |
|
return $this->host; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Set the host url. |
60
|
|
|
* |
61
|
|
|
* @param string $host |
62
|
|
|
* |
63
|
|
|
* @return self |
64
|
|
|
*/ |
65
|
120 |
|
public function setHost($host) |
66
|
|
|
{ |
67
|
120 |
|
$this->host = trim(utf8_encode($host)); |
68
|
|
|
|
69
|
120 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the blocked status. |
74
|
|
|
* |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
57 |
|
public function isBlocked() |
78
|
|
|
{ |
79
|
57 |
|
return $this->blocked; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set the blocked status. |
84
|
|
|
* |
85
|
|
|
* @param bool $blocked |
86
|
|
|
* |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
120 |
|
public function setBlocked($blocked) |
90
|
|
|
{ |
91
|
120 |
|
$this->blocked = (bool) $blocked; |
92
|
|
|
|
93
|
120 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/* ----------------------------------------------------------------- |
97
|
|
|
| Main Methods |
98
|
|
|
| ----------------------------------------------------------------- |
99
|
|
|
*/ |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Make a spammer instance. |
103
|
|
|
* |
104
|
|
|
* @param string $host |
105
|
|
|
* @param bool $blocked |
106
|
|
|
* |
107
|
|
|
* @return self |
108
|
|
|
*/ |
109
|
108 |
|
public static function make($host, $blocked = true) |
110
|
|
|
{ |
111
|
108 |
|
return new static($host, $blocked); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Check if the given host is the same as the spammer host. |
116
|
|
|
* |
117
|
|
|
* @param string $host |
118
|
|
|
* |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
3 |
|
public function isSameHost($host) |
122
|
|
|
{ |
123
|
3 |
|
return $this->host() === trim(utf8_encode($host)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/* ----------------------------------------------------------------- |
127
|
|
|
| Other Methods |
128
|
|
|
| ----------------------------------------------------------------- |
129
|
|
|
*/ |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get the instance as an array. |
133
|
|
|
* |
134
|
|
|
* @return array |
135
|
|
|
*/ |
136
|
6 |
|
public function toArray() |
137
|
|
|
{ |
138
|
|
|
return [ |
139
|
6 |
|
'host' => $this->host, |
140
|
6 |
|
'blocked' => $this->blocked, |
141
|
2 |
|
]; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Convert the object into something JSON serializable. |
146
|
|
|
* |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
3 |
|
public function jsonSerialize() |
150
|
|
|
{ |
151
|
3 |
|
return $this->toArray(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Convert the object to its JSON representation. |
156
|
|
|
* |
157
|
|
|
* @param int $options |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
3 |
|
public function toJson($options = 0) |
162
|
|
|
{ |
163
|
3 |
|
return json_encode($this->jsonSerialize(), $options); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|