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