1 | <?php declare(strict_types=1); |
||
16 | class Impersonator |
||
17 | { |
||
18 | /** @var Guard $guard */ |
||
19 | protected $guard; |
||
20 | |||
21 | /** @var Repository $config */ |
||
22 | protected $config; |
||
23 | |||
24 | /** @var UserProvider */ |
||
25 | protected $userProvider; |
||
26 | |||
27 | /** @var Store $session */ |
||
28 | protected $session; |
||
29 | |||
30 | /** @var Dispatcher $eventDispatcher */ |
||
31 | protected $eventDispatcher; |
||
32 | |||
33 | /** @var Authenticatable */ |
||
34 | protected $impersonationUser; |
||
35 | |||
36 | /** @var bool */ |
||
37 | protected $isForbidden; |
||
38 | |||
39 | const SESSION_NAME = 'pretend:_switch_user'; |
||
40 | |||
41 | 7 | public function __construct( |
|
55 | |||
56 | /** |
||
57 | * @throws HttpException Throw 403 exception if cannot find user |
||
58 | */ |
||
59 | 2 | public function exitImpersonation() |
|
74 | |||
75 | /** |
||
76 | * @throws HttpException Throw 403 exception if cannot find user |
||
77 | */ |
||
78 | 4 | protected function retrieveUser(string $username): Authenticatable |
|
92 | |||
93 | /** |
||
94 | * @throws HttpException Throw 403 exception if you try to impersonate yourself |
||
95 | * |
||
96 | * @param string $username Username of user you want to enter impersonate |
||
97 | */ |
||
98 | 4 | public function enterImpersonation(string $username) |
|
116 | |||
117 | 4 | public function isImpersonated(): bool |
|
121 | |||
122 | /** |
||
123 | * @throws HttpException Throw 403 exception if cannot find data in session |
||
124 | */ |
||
125 | 1 | public function continueImpersonation() |
|
131 | |||
132 | 1 | public function getImpersonatingIdentifier(): string |
|
136 | } |
||
137 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: