ThemeChanger::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 13
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Yajra\CMS\Themes;
4
5
use Closure;
6
7
class ThemeChanger
8
{
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param  \Illuminate\Http\Request $request
13
     * @param  \Closure $next
14
     * @return mixed
15
     */
16
    public function handle($request, Closure $next)
17
    {
18
        if ($theme = $request->query('cms-theme')) {
19
            $finder   = app('themes.view.finder');
20
            $basePath = config('themes.path.frontend', base_path('themes/frontend'));
21
            $finder->removeBasePath();
22
            $finder->setBasePath($basePath . DIRECTORY_SEPARATOR . $theme);
23
24
            config(['themes.frontend' => $theme]);
25
        }
26
27
        return $next($request);
28
    }
29
}
30