1 | <?php namespace Arcanedev\LaravelImpersonator; |
||
12 | class Impersonator implements Contracts\Impersonator |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Properties |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | |||
19 | /** @var \Illuminate\Contracts\Foundation\Application */ |
||
20 | protected $app; |
||
21 | |||
22 | /* ----------------------------------------------------------------- |
||
23 | | Constructor |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * Impersonator constructor. |
||
29 | * |
||
30 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
31 | */ |
||
32 | 39 | public function __construct(Application $app) |
|
36 | |||
37 | /* ----------------------------------------------------------------- |
||
38 | | Getters & Setters |
||
39 | | ----------------------------------------------------------------- |
||
40 | */ |
||
41 | |||
42 | /** |
||
43 | * Get the guard session instance. |
||
44 | * |
||
45 | * @return \Illuminate\Auth\AuthManager|\Arcanedev\LaravelImpersonator\Guard\SessionGuard |
||
46 | */ |
||
47 | 15 | protected function auth() |
|
51 | |||
52 | /** |
||
53 | * Get the session store instance. |
||
54 | * |
||
55 | * @return \Illuminate\Contracts\Session\Session |
||
56 | */ |
||
57 | 21 | protected function session() |
|
61 | |||
62 | /** |
||
63 | * Get the config repository. |
||
64 | * |
||
65 | * @return \Illuminate\Contracts\Config\Repository |
||
66 | */ |
||
67 | 36 | protected function config() |
|
71 | |||
72 | /** |
||
73 | * Get the event dispatcher. |
||
74 | * |
||
75 | * @return \Illuminate\Contracts\Events\Dispatcher |
||
76 | */ |
||
77 | 15 | protected function events() |
|
81 | |||
82 | /** |
||
83 | * Get the session key. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 21 | public function getSessionKey() |
|
91 | |||
92 | /** |
||
93 | * Get the impersonator id. |
||
94 | * |
||
95 | * @return int|null |
||
96 | */ |
||
97 | 18 | public function getImpersonatorId() |
|
101 | |||
102 | /* ----------------------------------------------------------------- |
||
103 | | Main Methods |
||
104 | | ----------------------------------------------------------------- |
||
105 | */ |
||
106 | |||
107 | /** |
||
108 | * Start the impersonation. |
||
109 | * |
||
110 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonator |
||
111 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonated |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | 27 | public function start(Impersonatable $impersonator, Impersonatable $impersonated) |
|
132 | |||
133 | /** |
||
134 | * Stop the impersonation. |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | 12 | public function stop() |
|
156 | |||
157 | /** |
||
158 | * Clear the impersonation. |
||
159 | */ |
||
160 | 15 | public function clear() |
|
164 | |||
165 | /** |
||
166 | * Find a user by the given id. |
||
167 | * |
||
168 | * @param int|string $id |
||
169 | * |
||
170 | * @return \Arcanedev\LaravelImpersonator\Contracts\Impersonatable |
||
171 | * |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | 30 | public function findUserById($id) |
|
178 | |||
179 | /* ----------------------------------------------------------------- |
||
180 | | Check Functions |
||
181 | | ----------------------------------------------------------------- |
||
182 | */ |
||
183 | |||
184 | /** |
||
185 | * Check if it's impersonating. |
||
186 | * |
||
187 | * @return bool |
||
188 | */ |
||
189 | 18 | public function isImpersonating() |
|
193 | |||
194 | /** |
||
195 | * Check if the impersonations is enabled. |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | 27 | public function isEnabled() |
|
203 | |||
204 | /* ----------------------------------------------------------------- |
||
205 | | Other Methods |
||
206 | | ----------------------------------------------------------------- |
||
207 | */ |
||
208 | |||
209 | /** |
||
210 | * Check the impersonation. |
||
211 | * |
||
212 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonator |
||
213 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $impersonated |
||
214 | * |
||
215 | * @throws Exceptions\ImpersonationException |
||
216 | */ |
||
217 | 27 | private function checkImpersonation(Impersonatable $impersonator, Impersonatable $impersonated) |
|
235 | } |
||
236 |