1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SixtyEightPublishers\User\ForgotPassword\Exception; |
6
|
|
|
|
7
|
|
|
use Throwable; |
8
|
|
|
use SixtyEightPublishers\User\Common\Exception\RuntimeException; |
9
|
|
|
|
10
|
|
|
final class PasswordRequestProcessException extends RuntimeException |
11
|
|
|
{ |
12
|
|
|
public const CODE_MISSING_REQUEST = 2001; |
13
|
|
|
public const CODE_EXPIRED_REQUEST = 2002; |
14
|
|
|
|
15
|
|
|
/** @var mixed */ |
16
|
|
|
private $uid; |
17
|
|
|
|
18
|
|
|
/** @var mixed */ |
19
|
|
|
private $rid; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param mixed $uid |
23
|
|
|
* @param mixed $rid |
24
|
|
|
* @param string $message |
25
|
|
|
* @param int $code |
26
|
|
|
* @param \Throwable|null $previous |
27
|
|
|
*/ |
28
|
|
|
public function __construct($uid, $rid, string $message, int $code = 0, Throwable $previous = NULL) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($message, $code, $previous); |
31
|
|
|
|
32
|
|
|
$this->uid = $uid; |
33
|
|
|
$this->rid = $rid; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param mixed $uid |
38
|
|
|
* @param mixed $rid |
39
|
|
|
* |
40
|
|
|
* @return \SixtyEightPublishers\User\ForgotPassword\Exception\PasswordRequestProcessException |
41
|
|
|
*/ |
42
|
|
|
public static function missingRequest($uid, $rid): self |
43
|
|
|
{ |
44
|
|
|
return new static($uid, $rid, sprintf( |
45
|
|
|
'Missing request for UID %s and RID %s', |
46
|
|
|
(string) $uid, |
47
|
|
|
(string) $rid |
48
|
|
|
), self::CODE_MISSING_REQUEST); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param mixed $uid |
53
|
|
|
* @param mixed $rid |
54
|
|
|
* |
55
|
|
|
* @return \SixtyEightPublishers\User\ForgotPassword\Exception\PasswordRequestProcessException |
56
|
|
|
*/ |
57
|
|
|
public static function expiredRequest($uid, $rid): self |
58
|
|
|
{ |
59
|
|
|
return new static($uid, $rid, sprintf( |
60
|
|
|
'Request for UID %s and RID %s is already expired', |
61
|
|
|
(string) $uid, |
62
|
|
|
(string) $rid |
63
|
|
|
), self::CODE_EXPIRED_REQUEST); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
public function getUid() |
70
|
|
|
{ |
71
|
|
|
return $this->uid; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
public function getRid() |
78
|
|
|
{ |
79
|
|
|
return $this->rid; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function isMissingRequest(): bool |
86
|
|
|
{ |
87
|
|
|
return $this->code === self::CODE_MISSING_REQUEST; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
|
|
public function isExpiredRequest(): bool |
94
|
|
|
{ |
95
|
|
|
return $this->code === self::CODE_EXPIRED_REQUEST; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|