TenantServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 34
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 17 2
A boot() 0 2 1
1
<?php
2
3
namespace App\Providers;
4
5
use App\Services\TenantManager;
6
use Illuminate\Support\ServiceProvider;
7
8
class TenantServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Register services.
12
     *
13
     * @return void
14
     */
15
    public function register()
16
    {
17
        $manager = new TenantManager();
18
19
        $this->app->instance(TenantManager::class, $manager);
20
        $this->app->bind(Tenant::class, function () use ($manager) {
21
            return $manager->getTenant();
22
        });
23
24
        $this->app['db']->extend('tenant', function ($config, $name) use ($manager) {
25
            $tenant = $manager->getTenant();
26
27
            if ($tenant) {
28
                $config['database'] = 'tenant_'.$tenant->id;
29
            }
30
31
            return $this->app['db.factory']->make($config, $name);
32
        });
33
    }
34
35
    /**
36
     * Bootstrap services.
37
     *
38
     * @return void
39
     */
40
    public function boot()
41
    {
42
        //
43
    }
44
}
45