1 | <?php |
||
18 | class Impersonator implements ImpersonatorContract |
||
19 | { |
||
20 | /* ----------------------------------------------------------------- |
||
21 | | Properties |
||
22 | | ----------------------------------------------------------------- |
||
23 | */ |
||
24 | |||
25 | /** @var \Illuminate\Contracts\Foundation\Application */ |
||
26 | protected $app; |
||
27 | |||
28 | /* ----------------------------------------------------------------- |
||
29 | | Constructor |
||
30 | | ----------------------------------------------------------------- |
||
31 | */ |
||
32 | |||
33 | /** |
||
34 | * Impersonator constructor. |
||
35 | * |
||
36 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
37 | */ |
||
38 | 84 | public function __construct(Application $app) |
|
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Getters & Setters |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Get the guard session instance. |
||
50 | * |
||
51 | * @return \Illuminate\Auth\AuthManager|\Arcanedev\LaravelImpersonator\Guard\SessionGuard |
||
52 | */ |
||
53 | 36 | protected function auth() |
|
57 | |||
58 | /** |
||
59 | * Get the session store instance. |
||
60 | * |
||
61 | * @return \Illuminate\Contracts\Session\Session |
||
62 | */ |
||
63 | 48 | protected function session() |
|
67 | |||
68 | /** |
||
69 | * Get the config repository. |
||
70 | * |
||
71 | * @return \Illuminate\Contracts\Config\Repository |
||
72 | */ |
||
73 | 64 | protected function config() |
|
77 | |||
78 | /** |
||
79 | * Get the event dispatcher. |
||
80 | * |
||
81 | * @return \Illuminate\Contracts\Events\Dispatcher |
||
82 | */ |
||
83 | 32 | protected function events() |
|
87 | |||
88 | /** |
||
89 | * Get the session key. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 48 | public function getSessionKey(): string |
|
97 | |||
98 | /** |
||
99 | * Get the session guard. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 48 | public function getSessionGuard(): string |
|
107 | |||
108 | /** |
||
109 | * Get the impersonator id. |
||
110 | * |
||
111 | * @return int|null |
||
112 | */ |
||
113 | 36 | public function getImpersonatorId(): ?int |
|
117 | |||
118 | /** |
||
119 | * Get the impersonator guard. |
||
120 | * |
||
121 | * @return string|null |
||
122 | */ |
||
123 | 32 | public function getImpersonatorGuard(): ?string |
|
128 | |||
129 | /* ----------------------------------------------------------------- |
||
130 | | Main Methods |
||
131 | | ----------------------------------------------------------------- |
||
132 | */ |
||
133 | |||
134 | /** |
||
135 | * Start the impersonation. |
||
136 | * |
||
137 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
138 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
139 | * @param string|null $guard |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | 48 | public function start(Impersonatable $impersonator, Impersonatable $impersonated, $guard = null): bool |
|
164 | |||
165 | /** |
||
166 | * Stop the impersonation. |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 28 | public function stop(): bool |
|
192 | |||
193 | /** |
||
194 | * Clear the impersonation. |
||
195 | */ |
||
196 | 28 | public function clear(): void |
|
203 | |||
204 | /** |
||
205 | * Get the impersonator from session. |
||
206 | * |
||
207 | * @return \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed|null |
||
208 | * |
||
209 | * @throws \Exception |
||
210 | */ |
||
211 | 28 | protected function getImpersonatorFromSession() |
|
222 | |||
223 | /* ----------------------------------------------------------------- |
||
224 | | Check Methods |
||
225 | | ----------------------------------------------------------------- |
||
226 | */ |
||
227 | |||
228 | /** |
||
229 | * Check if it's impersonating. |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | 36 | public function isImpersonating(): bool |
|
240 | |||
241 | /** |
||
242 | * Check if the impersonations is enabled. |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | 48 | public function isEnabled(): bool |
|
250 | |||
251 | /* ----------------------------------------------------------------- |
||
252 | | Other Methods |
||
253 | | ----------------------------------------------------------------- |
||
254 | */ |
||
255 | |||
256 | /** |
||
257 | * Check the impersonation. |
||
258 | * |
||
259 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
260 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
261 | */ |
||
262 | 48 | private function checkImpersonation(Impersonatable $impersonator, Impersonatable $impersonated): void |
|
269 | |||
270 | /** |
||
271 | * Check if the impersonation is enabled. |
||
272 | * |
||
273 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
274 | */ |
||
275 | 48 | private function mustBeEnabled(): void |
|
282 | |||
283 | /** |
||
284 | * Check the impersonator and the impersonated are different. |
||
285 | * |
||
286 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
287 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
288 | * |
||
289 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
290 | */ |
||
291 | 44 | private function mustBeDifferentImpersonatable(Impersonatable $impersonator, Impersonatable $impersonated): void |
|
297 | |||
298 | /** |
||
299 | * Check the impersonator. |
||
300 | * |
||
301 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonator |
||
302 | * |
||
303 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
304 | */ |
||
305 | 40 | private function checkImpersonater(Impersonatable $impersonator): void |
|
310 | |||
311 | /** |
||
312 | * Check the impersonated. |
||
313 | * |
||
314 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
315 | * |
||
316 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
317 | */ |
||
318 | 36 | private function checkImpersonated(Impersonatable $impersonated): void |
|
323 | |||
324 | /** |
||
325 | * Remember the impersonator. |
||
326 | * |
||
327 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonator |
||
328 | */ |
||
329 | 32 | private function rememberImpersonater(Impersonatable $impersonator) |
|
336 | } |
||
337 |
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: