RebindKernelContainer::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
rs 10
1
<?php
2
3
namespace SwooleTW\Http\Server\Resetters;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Contracts\Http\Kernel;
7
use SwooleTW\Http\Server\Sandbox;
8
9
class RebindKernelContainer implements ResetterContract
10
{
11
    /**
12
     * @var \Illuminate\Contracts\Container\Container
13
     */
14
    protected $app;
15
16
    /**
17
     * "handle" function for resetting app.
18
     *
19
     * @param \Illuminate\Contracts\Container\Container $app
20
     * @param \SwooleTW\Http\Server\Sandbox $sandbox
21
     *
22
     * @return \Illuminate\Contracts\Container\Container
23
     */
24
    public function handle(Container $app, Sandbox $sandbox)
25
    {
26
        if ($sandbox->isLaravel()) {
27
            $kernel = $app->make(Kernel::class);
28
29
            $closure = function () use ($app) {
30
                $this->app = $app;
31
            };
32
33
            $resetKernel = $closure->bindTo($kernel, $kernel);
34
            $resetKernel();
35
        }
36
37
        return $app;
38
    }
39
}
40