XHProfServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 3
b 0
f 0
nc 3
nop 0
dl 0
loc 16
rs 9.9666
1
<?php
2
3
namespace Bavix\XHProf;
4
5
use Bavix\XHProf\Middleware\XHProfMiddleware;
6
use Bavix\XHProf\Services\XHProfService;
7
use Illuminate\Contracts\Http\Kernel;
8
use Illuminate\Support\ServiceProvider;
9
10
class XHProfServiceProvider extends ServiceProvider
11
{
12
13
    /**
14
     * @return void
15
     */
16
    public function boot(): void
17
    {
18
        if ($this->app->runningInConsole()) {
19
            return;
20
        }
21
22
        $this->mergeConfigFrom(
23
            dirname(__DIR__) . '/config/config.php',
24
            'xhprof'
25
        );
26
27
        $this->app->singleton(XHProfMiddleware::class);
28
        $this->app->singleton(XHProfService::class);
29
30
        if (config('xhprof.global_middleware', false)) {
31
            $this->extraMiddleware(XHProfMiddleware::class);
32
        }
33
    }
34
35
    /**
36
     * @param string $className
37
     */
38
    public function extraMiddleware(string $className): void
39
    {
40
        /**
41
         * @var \Illuminate\Foundation\Http\Kernel $kernel
42
         */
43
        $kernel = $this->app[Kernel::class];
44
        $kernel->pushMiddleware($className);
45
    }
46
47
}
48