1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ridvanbaluyos\Pwned; |
4
|
|
|
|
5
|
|
|
use \Ridvanbaluyos\Pwned\Pwned as Pwned; |
6
|
|
|
/** |
7
|
|
|
* Getting all breaches for an account |
8
|
|
|
* https://haveibeenpwned.com/API/v2#BreachesForAccount |
9
|
|
|
* |
10
|
|
|
* @package Pwned |
11
|
|
|
* @author Ridvan Baluyos <[email protected]> |
12
|
|
|
* @link https://github.com/ridvanbaluyos/haveibeenpwned |
13
|
|
|
* @license MIT |
14
|
|
|
*/ |
15
|
|
|
class BreachedAccount extends Pwned |
16
|
|
|
{ |
17
|
|
|
private $account; |
18
|
|
|
private $domain; |
19
|
|
|
private $truncateResponse; |
20
|
|
|
private $includeUnverified; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* BreachedAccount constructor. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* This function gets all breaches for an account. |
32
|
|
|
* |
33
|
|
|
* @param string $account |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function get(): array |
37
|
|
|
{ |
38
|
|
|
// No account has been set, return empty array. |
39
|
|
|
if (!isset($this->account)) return []; |
40
|
|
|
|
41
|
|
|
$filters = []; |
42
|
|
|
$url = $this->endpoint . 'breachedaccount/' . $this->account; |
43
|
|
|
|
44
|
|
|
// Return only the name of the breach. |
45
|
|
|
if (isset($this->truncateResponse)) { |
46
|
|
|
$filters['truncateResponse'] = $this->truncateResponse; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// Filter domain, if available. |
50
|
|
|
if (isset($this->domain)) { |
51
|
|
|
$filters['domain'] = $this->domain; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Include unverified domains? |
55
|
|
|
if (isset($this->includeUnverified)) { |
56
|
|
|
$filters['includeUnverified'] = $this->includeUnverified; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$url = $this->setFilters($url, $filters); |
60
|
|
|
$breachedAccounts = $this->requestGet($url); |
61
|
|
|
|
62
|
|
|
return $breachedAccounts; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sets the account. |
67
|
|
|
* |
68
|
|
|
* @param string $account |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
|
|
public function setAccount(string $account) |
72
|
|
|
{ |
73
|
|
|
$this->account = $account; |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sets if response should be truncated. Only return the name of the breach. |
79
|
|
|
* |
80
|
|
|
* @param bool $isTruncated |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function setTruncatedResponse(string $truncateResponse = 'true') |
84
|
|
|
{ |
85
|
|
|
$this->truncateResponse = $truncateResponse; |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets if response should include unverified domains. |
91
|
|
|
* |
92
|
|
|
* @param bool $includeUnverified |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function setIncludeUnverified(string $includeUnverified = 'true') |
96
|
|
|
{ |
97
|
|
|
$this->includeUnverified = $includeUnverified; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sets the domain filter. Filter the results only to the domain specified. |
103
|
|
|
* |
104
|
|
|
* @param string $domain |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
|
|
public function setDomain(string $domain) |
108
|
|
|
{ |
109
|
|
|
$this->domain = $domain; |
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
} |