1 | <?php |
||
2 | |||
3 | namespace Spatie\DemoMode; |
||
4 | |||
5 | use Closure; |
||
6 | use Illuminate\Config\Repository; |
||
7 | use Illuminate\Http\RedirectResponse; |
||
8 | use Illuminate\Http\Request; |
||
9 | |||
10 | class DemoMode |
||
11 | { |
||
12 | /** @var array */ |
||
13 | protected $config; |
||
14 | |||
15 | public function __construct(Repository $config) |
||
16 | { |
||
17 | $this->config = $config->get('demo-mode'); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * Handle an incoming request. |
||
22 | * |
||
23 | * @param \Illuminate\Http\Request $request |
||
24 | * @param \Closure $next |
||
25 | * |
||
26 | * @return mixed |
||
27 | */ |
||
28 | public function handle($request, Closure $next) |
||
29 | { |
||
30 | if (!$this->config['enabled']) { |
||
31 | return $next($request); |
||
32 | } |
||
33 | |||
34 | if ($this->protectedByDemoMode($request)) { |
||
35 | if (!app(DemoGuard::class)->hasDemoAccess($request)) { |
||
36 | return new RedirectResponse($this->config['redirect_unauthorized_users_to_url']); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | return $next($request); |
||
41 | } |
||
42 | |||
43 | protected function protectedByDemoMode(Request $request): bool |
||
0 ignored issues
–
show
|
|||
44 | { |
||
45 | return true; |
||
46 | } |
||
47 | } |
||
48 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.