Passed
Pull Request — 1.2 (#405)
by
unknown
08:49
created

SupportSubdomainRouting::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
nc 2
nop 2
dl 0
loc 21
ccs 0
cts 12
cp 0
crap 6
rs 9.9
c 1
b 0
f 0
1
<?php
2
3
namespace A17\Twill\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use URL;
8
use View;
9
10
class SupportSubdomainRouting
11
{
12
    public function handle(Request $request, Closure $next)
13
    {
14
        $parameter = 'subdomain';
15
        $subdomain = $request->route()->parameter($parameter) ?? key(config('twill.app_names'));
16
17
        // Set subdomain as default URL parameter to not have
18
        // to add it manually when using route helpers
19
        URL::defaults([$parameter => $subdomain]);
20
21
        $blockLayout = View::exists($subdomain . '.layouts.block') ? ($subdomain . '.layouts.block') : 'site.layouts.blocks';
22
23
        config([
24
            'app.name' => config('twill.app_names')[$subdomain] ?? config('app.name'),
25
            'twill-navigation' => config('twill-navigation')[$subdomain] ?? key(config('twill-navigation')),
26
            'twill.dashboard.modules' => config('twill.dashboard.modules')[$subdomain] ?? key(config('twill.dashboard.modules')),
27
            'twill.block_editor.block_single_layout' => $blockLayout,
28
        ]);
29
30
        $request->route()->forgetParameter($parameter);
31
32
        return $next($request);
33
    }
34
}
35