Completed
Push — master ( 5df011...747e00 )
by Changwan
03:50
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Foundation;
3
4
use Wandu\DI\Container;
5
use Wandu\Foundation\Contracts\KernelInterface;
6
7
class Application extends Container
8
{
9
    const NAME = "Wandu";
10
    const VERSION = "3.1-dev";
11
12
    /** @var \Wandu\Foundation\Contracts\KernelInterface */
13
    protected $kernel;
14
15
    /** @var \Wandu\Foundation\Application */
16
    public static $app;
17
18
    /**
19
     * @param \Wandu\Foundation\Contracts\KernelInterface $kernel
20
     */
21 4
    public function __construct(KernelInterface $kernel)
22
    {
23 4
        parent::__construct();
24 4
        $this->instance(KernelInterface::class, $this->kernel = $kernel);
25 4
        $this->alias('kernel', KernelInterface::class);
26 4
        $this->setAsGlobal();
27 4
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function boot()
33
    {
34
        if (!$this->isBooted) {
35
            $this->kernel->boot($this);
36
            parent::boot();
37
        }
38
        return $this;
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44
    public function execute()
45
    {
46
        $this->boot();
47
        return $this->kernel->execute($this);
48
    }
49
50
    /**
51
     * @return \Wandu\Foundation\Application
52
     */
53 4
    public function setAsGlobal()
54
    {
55 4
        $oldApp = static::$app;
56 4
        static::$app = $this;
57 4
        return $oldApp;
58
    }
59
}
60