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

SupportSubdomainRouting   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 23
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 21 2
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