1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arcanedev\LaravelImpersonator\Exceptions; |
6
|
|
|
|
7
|
|
|
use Arcanedev\LaravelImpersonator\Contracts\Impersonatable; |
8
|
|
|
use Exception; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ImpersonationException |
12
|
|
|
* |
13
|
|
|
* @author ARCANEDEV <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ImpersonationException extends Exception |
16
|
|
|
{ |
17
|
|
|
/* ----------------------------------------------------------------- |
18
|
|
|
| Main Methods |
19
|
|
|
| ----------------------------------------------------------------- |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Make a new exception. |
24
|
|
|
* |
25
|
|
|
* @param string $message |
26
|
|
|
* |
27
|
|
|
* @return static |
28
|
|
|
*/ |
29
|
12 |
|
public static function make(string $message): self |
30
|
|
|
{ |
31
|
12 |
|
return new static($message); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Make an exception when the impersonater and impersonated are same person. |
36
|
|
|
* |
37
|
|
|
* @return static |
38
|
|
|
*/ |
39
|
4 |
|
public static function selfImpersonation(): self |
40
|
|
|
{ |
41
|
4 |
|
return static::make('The impersonater & impersonated with must be different.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Make an exception when the impersonater cannot (or not allowed) impersonate. |
46
|
|
|
* |
47
|
|
|
* @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonater |
48
|
|
|
* |
49
|
|
|
* @return static |
50
|
|
|
*/ |
51
|
4 |
|
public static function cannotImpersonate(Impersonatable $impersonater): self |
52
|
|
|
{ |
53
|
4 |
|
return static::make( |
54
|
4 |
|
__("The impersonater with `:impersonator_name`=[:impersonator_id] doesn't have the ability to impersonate.", [ |
55
|
4 |
|
'impersonator_name' => $impersonater->getAuthIdentifierName(), |
56
|
4 |
|
'impersonator_id' => $impersonater->getAuthIdentifier(), |
57
|
|
|
]) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Make an exception when the impersonated cannot be impersonated. |
63
|
|
|
* |
64
|
|
|
* @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonated |
65
|
|
|
* |
66
|
|
|
* @return static |
67
|
|
|
*/ |
68
|
4 |
|
public static function cannotBeImpersonated(Impersonatable $impersonated): self |
69
|
|
|
{ |
70
|
4 |
|
return static::make( |
71
|
4 |
|
__('The impersonated with `:impersonated_name`=[:impersonated_id] cannot be impersonated.', [ |
72
|
4 |
|
'impersonated_name' => $impersonated->getAuthIdentifierName(), |
73
|
4 |
|
'impersonated_id' => $impersonated->getAuthIdentifier() |
74
|
|
|
]) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Make an exception when the impersonator and the impersonated are the same person. |
80
|
|
|
* |
81
|
|
|
* @return static |
82
|
|
|
*/ |
83
|
|
|
public static function impersonaterAndImpersonatedAreSame(): self |
84
|
|
|
{ |
85
|
|
|
return static::make( |
86
|
|
|
__('The impersonater & impersonated with must be different.') |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|