1 | <?php |
||
19 | class Impersonator implements ImpersonatorContract |
||
20 | { |
||
21 | /* ----------------------------------------------------------------- |
||
22 | | Properties |
||
23 | | ----------------------------------------------------------------- |
||
24 | */ |
||
25 | |||
26 | /** @var \Illuminate\Contracts\Foundation\Application */ |
||
27 | protected $app; |
||
28 | |||
29 | /* ----------------------------------------------------------------- |
||
30 | | Constructor |
||
31 | | ----------------------------------------------------------------- |
||
32 | */ |
||
33 | |||
34 | /** |
||
35 | * Impersonator constructor. |
||
36 | * |
||
37 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
38 | */ |
||
39 | 126 | public function __construct(Application $app) |
|
43 | |||
44 | /* ----------------------------------------------------------------- |
||
45 | | Getters & Setters |
||
46 | | ----------------------------------------------------------------- |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * Get the guard session instance. |
||
51 | * |
||
52 | * @return \Illuminate\Auth\AuthManager|\Arcanedev\LaravelImpersonator\Guard\SessionGuard |
||
53 | */ |
||
54 | 54 | protected function auth() |
|
58 | |||
59 | /** |
||
60 | * Get the session store instance. |
||
61 | * |
||
62 | * @return \Illuminate\Contracts\Session\Session |
||
63 | */ |
||
64 | 72 | protected function session() |
|
68 | |||
69 | /** |
||
70 | * Get the config repository. |
||
71 | * |
||
72 | * @return \Illuminate\Contracts\Config\Repository |
||
73 | */ |
||
74 | 96 | protected function config() |
|
78 | |||
79 | /** |
||
80 | * Get the event dispatcher. |
||
81 | * |
||
82 | * @return \Illuminate\Contracts\Events\Dispatcher |
||
83 | */ |
||
84 | 48 | protected function events() |
|
88 | |||
89 | /** |
||
90 | * Get the session key. |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | 72 | public function getSessionKey(): string |
|
98 | |||
99 | /** |
||
100 | * Get the session guard. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 72 | public function getSessionGuard(): string |
|
108 | |||
109 | /** |
||
110 | * Get the impersonator id. |
||
111 | * |
||
112 | * @return int|null |
||
113 | */ |
||
114 | 54 | public function getImpersonatorId(): ?int |
|
118 | |||
119 | /** |
||
120 | * Get the impersonator guard. |
||
121 | * |
||
122 | * @return string|null |
||
123 | */ |
||
124 | 48 | public function getImpersonatorGuard(): ?string |
|
129 | |||
130 | /* ----------------------------------------------------------------- |
||
131 | | Main Methods |
||
132 | | ----------------------------------------------------------------- |
||
133 | */ |
||
134 | |||
135 | /** |
||
136 | * Start the impersonation. |
||
137 | * |
||
138 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
139 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
140 | * @param string|null $guard |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 72 | public function start(Impersonatable $impersonator, Impersonatable $impersonated, $guard = null): bool |
|
165 | |||
166 | /** |
||
167 | * Stop the impersonation. |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | 42 | public function stop(): bool |
|
193 | |||
194 | /** |
||
195 | * Clear the impersonation. |
||
196 | */ |
||
197 | 42 | public function clear(): void |
|
204 | |||
205 | /** |
||
206 | * Get the impersonator from session. |
||
207 | * |
||
208 | * @return \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed|null |
||
209 | * |
||
210 | * @throws \Exception |
||
211 | */ |
||
212 | 42 | protected function getImpersonatorFromSession() |
|
223 | |||
224 | /* ----------------------------------------------------------------- |
||
225 | | Check Methods |
||
226 | | ----------------------------------------------------------------- |
||
227 | */ |
||
228 | |||
229 | /** |
||
230 | * Check if it's impersonating. |
||
231 | * |
||
232 | * @return bool |
||
233 | */ |
||
234 | 54 | public function isImpersonating(): bool |
|
241 | |||
242 | /** |
||
243 | * Check if the impersonations is enabled. |
||
244 | * |
||
245 | * @return bool |
||
246 | */ |
||
247 | 72 | public function isEnabled(): bool |
|
251 | |||
252 | /* ----------------------------------------------------------------- |
||
253 | | Other Methods |
||
254 | | ----------------------------------------------------------------- |
||
255 | */ |
||
256 | |||
257 | /** |
||
258 | * Check the impersonation. |
||
259 | * |
||
260 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
261 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
262 | */ |
||
263 | 72 | private function checkImpersonation(Impersonatable $impersonator, Impersonatable $impersonated): void |
|
270 | |||
271 | /** |
||
272 | * Check if the impersonation is enabled. |
||
273 | * |
||
274 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
275 | */ |
||
276 | 72 | private function mustBeEnabled(): void |
|
283 | |||
284 | /** |
||
285 | * Check the impersonator and the impersonated are different. |
||
286 | * |
||
287 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
288 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
289 | * |
||
290 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
291 | */ |
||
292 | 66 | private function mustBeDifferentImpersonatable(Impersonatable $impersonator, Impersonatable $impersonated): void |
|
298 | |||
299 | /** |
||
300 | * Check the impersonator. |
||
301 | * |
||
302 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
303 | * |
||
304 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
305 | */ |
||
306 | 60 | private function checkImpersonater(Impersonatable $impersonator): void |
|
311 | |||
312 | /** |
||
313 | * Check the impersonated. |
||
314 | * |
||
315 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
316 | * |
||
317 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
318 | */ |
||
319 | 54 | private function checkImpersonated(Impersonatable $impersonated): void |
|
324 | |||
325 | /** |
||
326 | * Remember the impersonator. |
||
327 | * |
||
328 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonator |
||
329 | */ |
||
330 | 48 | private function rememberImpersonater(Impersonatable $impersonator) |
|
337 | } |
||
338 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: