Application::createContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Padawan\Framework;
4
5
use DI\Container;
6
use DI\ContainerBuilder;
7
use React\EventLoop\Factory;
8
use Symfony\Component\Console\Application as BaseApplication;
9
10
define("PADAWAN_VERSION", "0.3");
11
define("STUBS_DIR", dirname(dirname(dirname(__DIR__))) . '/stubs');
12
13
/**
14
 * Class Application
15
 */
16
abstract class Application extends BaseApplication
17
{
18
    public static $eventLoop;
19
    public function __construct($name = "Padawan", $loop = null)
20
    {
21
        parent::__construct($name, PADAWAN_VERSION);
22
        $this->createContainer();
23
        $this->setAutoExit(false);
24
        $this->loadCommands();
25
        if ($loop) {
26
            self::$eventLoop = $loop;
27
        } else {
28
            self::$eventLoop = Factory::create();
29
        }
30
    }
31
32
    public function getContainer()
33
    {
34
        return $this->container;
35
    }
36
37
    abstract protected function loadCommands();
38
39
    private function createContainer()
40
    {
41
        $builder = new ContainerBuilder;
42
        $builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache);
43
        $builder->addDefinitions(__DIR__ . '/DI/config.php');
44
        $this->container = $builder->build();
45
    }
46
47
    /** @var Container */
48
    protected $container;
49
}
50